Yomguithereal / baobab

JavaScript & TypeScript persistent and optionally immutable data tree with cursors.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get/Select on Various Array Entries

jemos opened this issue · comments

Hi,

Is it possible to use .get({param: value}) and it return all the entries that have the property param = value?

As far as I know it will only return the first element found.

Thank you.

Hi,
I think it is not possible.
But there is an easy solution for your problem:

{
  items: [{
    id: 1,
    name: 'Item1'
  }, {
    id: 2,
    name: 'Item1'
  }]
}

var result = tree.get('items').filter(function(item) {
  return item.name === 'Item1';
});

Thanks for that hint davincho.