0

我正在使用下划线 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和处属性值最小的对象的索引cb如果有共享相同的对象,我只想获取每个对象的 1 个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
4

1 回答 1

0

您可以使用 Filter 函数返回一个数组,其中包含通过所提供函数测试的项目。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

于 2013-10-20T23:00:28.443 回答