当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - 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' });

网友答案:

You can use _.filter() instead:

_.filter(data, function(item){
  return _.contains(item, "value4");
});
分享给朋友:
您可能感兴趣的文章:
随机阅读: