Skip to content

Latest commit

 

History

History
63 lines (45 loc) · 1.38 KB

collections.md

File metadata and controls

63 lines (45 loc) · 1.38 KB
findBy
  const collection = [
    {id: 1, user: { name: 'Foo' }},
    {id: 2, user: { name: 'Bar' }}
  ]

  collection.findBy('id', 1) // Returns {id: 1, user: { name: 'Foo }}

  collection.findBy('user.name', 'Bar') //Returns {id: 2, user: { name: 'Bar' }}
findById
  const collection = [
    {id: 1, user: { name: 'Foo' }},
    {id: 2, user: { name: 'Bar' }}
  ]

  collection.findById(1) // Returns {id: 1, user: { name: 'Foo }}
where
  const collection = [
    {id: 1, user: { name: 'Foo' }},
    {id: 2, user: { name: 'Bar' }},
    {id: 3, user: { name: 'Bar' }}
  ]

  collection.where('id', 1) // Returns [{id: 1, user: { name: 'Foo }}]

  collection.where('user.name', 'Bar') // Returns [{id: 2, user: { name: 'Bar' }}, {id: 3, user: { name: 'Bar' }}]
extract
  const collection = [
    {id: 1, user: { name: 'Foo' }},
    {id: 2, user: { name: 'Bar' }},
    {id: 3, user: { name: 'Bar' }}
  ]

  collection.extract(['id']) // Returns [{id: 1}, {id: 2}, {id: 3}]

  collection.where(['id', 'test']) // Returns [{id: 1, test: undefined}, {id: 2, test: undefined}, {id: 3, test: undefined}]