Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

arrobj

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

arrobj

Array and Object handling

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

arrobj


Easily modify Arrays and Objects in javascript

Installation

  • via npm:
npm install arrobj
  • via bower
bower install arrobj

Usage

  • In node:
// vanilla javascript
const arrobj = require("arrobj");
// es6 syntax
import * as arrobj from "arrobj";
  • In browser:
<script src="path/to/arrobj.js"></script>

Convert Array to Object

Below code:

var values = ['bliss', 21, ['soccer', 'basketball']];
var key = ['name', 'age', 'sports'];
console.log(arrobj.toObj(values, key));

Will create object:

{
  name: 'bliss',
  age: 21,
  sports: ['soccer', 'basketball']
}

If the key array is shorter than the values array, the index of the values in the array will used instead. The produced array for the above use case will be:

{
  0: 'bliss',
  1: 21,
  2: ['soccer', 'basketball']
}

Convert Object to Array

To convert an object to an array, the below case:

var obj = {
  name: 'bliss',
  age: 21,
  sports: ['soccer', 'basketball']
};

console.log(arr.toArr(obj));

Will produce array:

['bliss', 21, ['soccer', 'basketball']]

Other Methods

Arrays

  • isFlat(array): Checks if an array has a nested array.

  • isEqual(array1, array2): Compares two arrays by length.

  • isSame(array1, array2): Checks if the values in the array are the same, works for deep level comparison.

  • Arr(array): Checks if an argument is an array.

Objects

  • isObj(obj): Checks if argument is an object, returns true or false.

Contributing

  • Fork this repo.
  • clone and do you.
  • send a pull request.

FAQs

Package last updated on 27 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc