我正在使用下划线js,我有一个对象数组。
[{"a":"j1","b":1,"c":1,"life":1},{"a":"j2","b":5,"c":7,"life":5},{"a":"j3","b":9,"c":0,"life":9},{"a":"j4","b":4,"c":1,"life":4}]
我想获取b
和c
的属性值最小的对象的索引。我只想获得每个对象中的一个,以防对象共享相同的b
和c
我有这些递归函数
groupByMulti: (obj, values, context) ->
if (!values.length)
return obj;
byFirst = _.groupBy(obj, values[0], context)
rest = values.slice(1)
for i in byFirst
byFirst[i] = groupByMulti(byFirst[i], rest, context)
return byFirst
答案 0 :(得分:0)
您可以使用Filter函数返回一个数组,其中包含通过提供的函数测试的项目。
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter