如何仅在数组的第一个元素上使用_.reduce
答
您可以使用Array.prototype.slice
,使阵列的第一n
元素的(临时)副本:
_.reduce(myArray.slice(0, n), ...);
如果有数组这将只用他们都在不到n
元素。
答
如何使用_.first得到要减少项目的数量:
// reduce the first 100 items in the array
var result = _.reduce(_.first(data, 100), fn, memo)
您可以使用['_.slice'(https://lodash.com/docs#slice) –
@hege_hegedus这是“lodash”,而不是“下划线”... – Alnitak