1.0.0 • Published 4 years ago

index_object_by_array v1.0.0

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
4 years ago

Indexed object from array.

Create an object with indexes objects from array selecting a key.

Usage

const idxKey = require('index_array_by');

let arr = [
    { product: 'milk', id: 1, price: 500 },
    { product: 'bread', id: 2, price: 300 },
    { product: 'coffee', id: 3, price: 900 },
];

let result = idxArrBy(arr,'id');
console.log(result);

{ '1': { product: 'milk', id: 1, price: 500 },
  '2': { product: 'bread', id: 2, price: 300 },
  '3': { product: 'coffee', id: 3, price: 900 } }
  
  result[1]
  { product: 'milk', id: 1, price: 500 }

Test

npm test