Skip to content

Small helper for finding elements in an array by a key

License

Notifications You must be signed in to change notification settings

MoritzKn/find-by

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Find By

Build Status

Small helper to assist you with finding/filtering elements in an array by a specific key.

Install

npm install find-by --save

Example

const by = require('find-by')

const list = [
  { title: 'A New Hope', episode: 'IV' },
  { title: 'The Empire Strikes Back', episode: 'V' },
  { title: 'Return of the Jedi', episode: 'VI' }
]

console.log(list.find(by('episode', 'V')).title)
// => The Empire Strikes Back

For common keys there are also the shorter versions by.id, by.slug and by.type:

const by = require('find-by')

const list = [
  { id: 15, name: 'Foo' },
  { id: 42, name: 'Bar' },
  { id: 10, name: 'Baz' }
]

console.log(list.find(by.id(42)).name)
// => Bar

About

Small helper for finding elements in an array by a key

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published