JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q33962F
  • License MIT

Convert arrays into objects by using unique fields.

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

Patreon PayPal AMA Version Downloads Get help on Codementor

Convert arrays into objects by using unique fields.

☁️ Installation

$ npm i --save arr-obj

📋 Example

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.

💰 Donations

Another way to support the development of my open-source modules is to set up a recurring donation, via Patreon. 🚀

PayPal donations are appreciated too! Each dollar helps.

Thanks! ❤️

📜 License

MIT © Ionică Bizău