Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Underscore.js _.where finding sub objects

I have a data object with nested arrays. I'm wondering if Underscore can find the value inside an array inside the object.

Example:

var data = {
  'a': 'value',
  'b': 'value2',
  'c': [ 'value3', 'value4', 'value5']
}

_.where(data, { c: 'value4' });
like image 519
Fastmover Avatar asked Jun 11 '13 21:06

Fastmover


1 Answers

You can use _.filter() instead:

_.filter(data, function(item){
  return _.contains(item, "value4");
});
like image 147
idbehold Avatar answered Oct 18 '22 22:10

idbehold