扫码一下
查看教程更方便
_.findwhere(list, properties)
findwhere() 方法查看列表中的每个值,返回与属性中列出的键值对匹配的第一个匹配对。
var _ = require('underscore');
var list = [{"title": "learn java", "author": "sam", "cost": 100},
{"title": "learn scala", "author": "joe", "cost": 200},
{"title": "learn c", "author": "sam", "cost": 200} ]
//示例 1. 查找作者为 sam 的对象
var result = _.findwhere(list, { "author": "sam" });
console.log(result);
//示例 2. 查找花费200的对象
var result = _.findwhere(list, { "cost": 200 });
上面示例运行结果如下