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

返回


语法

_.indexby(list, iteratee, [context])

indexby() 方法获取由提供的 iteratee 方法返回的索引分组的拆分列表。

示例

var _ = require('underscore');
var list = [{"title": "learn java", "author": "sam", "cost": 100},
   {"title": "learn scala", "author": "joe", "cost": 200},
   {"title": "learn c", "author": "julie", "cost": 300} ]
//示例 1. 调用 indexby 方法以获取按 cost 索引的对象
var result = _.indexby(list, 'cost');
console.log(result);
//示例 2. 调用 indexby 方法以获取按 author 索引的对象
result = _.indexby(list, 'author')
console.log(result)

上面示例运行结果如下

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


返回

查看笔记

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