Package Exports
- arr-obj
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (arr-obj) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
arr-obj

Convert arrays into objects by using unique fields.
Installation
$ npm i --save arr-objExample
"use strict";
const arrObj = require("arr-obj");
let arr = [
{ name: "Alice", location: { name: "Earth" } },
{ name: "Bob", location: { name: "Mars" } }
];
console.log(arrObj(arr, "name"));
// { Alice: { name: 'Alice', location: { name: 'Earth' } },
// Bob: { name: 'Bob', location: { name: 'Mars' } } }
console.log(arrObj(arr, "location.name", true));
// { Earth: { name: 'Alice', location: { name: 'Earth' } },
// Mars: { name: 'Bob', location: { name: 'Mars' } } }
console.log(arrObj([1, 4, 9, 16], c => {
return Math.sqrt(c);
}));
// { '1': 1, '2': 4, '3': 9, '4': 16 }Documentation
arrObj(arr, by, deep)
Convert an array into object by using unique fields.
Params
- Array
arr: The input array. - String|Function
by: The field name to use in the object keys or a function returning this value. - Boolean
deep: Use this for accessing nested objects in the array elements.
Return
- Object The result object.
How to contribute
Have an idea? Found a bug? See how to contribute.
Where is this library used?
If you are using this library in one of your projects, add it in this list. ✨