underscore.js 集合 findwhere 方法——迹忆客-ag捕鱼王app官网

返回 underscore.js 集合


语法

_.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 });

上面示例运行结果如下

underscore.js 集合 findwhere 方法运行结果


返回 underscore.js 集合

查看笔记

扫码一下
查看教程更方便
网站地图