just-index
TypeScript icon, indicating that this package has built-in type declarations

4.2.0 • Public • Published

just-index

Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.

🍦 Try it

npm install just-index
yarn add just-index

Return an object from an array, keyed by the value at the given id

import index from 'just-index';

index([{id: 'first', val: 1}, {id: 'second', val: 2}], 'id');
// {first: {id: 'first', val: 1}, second: {id: 'second', val: 2}}
index([{id: 'first', val: 1}, null], 'id'); // {first: {id: 'first', val: 1}}
index([], 'id'); // {}
index([], null); // undefined
index({}, 'id'); // undefined

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i just-index

      Weekly Downloads

      584

      Version

      4.2.0

      License

      MIT

      Unpacked Size

      5.73 kB

      Total Files

      9

      Last publish

      Collaborators

      • angus-c