【发布时间】:2015-06-19 08:24:06
【问题描述】:
这是输入:
[{animal: "cat"}, {animal:"dog}}
输出将是:
[{animal: "cat", idx: 1}, {animal: "dog", idx: 2}]
有没有人知道如何在 Lodash/Underscore.js 中做到这一点?
【问题讨论】:
-
_.map(input, function(x, i) { return _.extend({idx:i}, x); })?
标签: javascript underscore.js lodash