【发布时间】:2015-09-26 11:42:15
【问题描述】:
我有以下代码来创建一个简单的机器语言命令数组。
// to ensure consistency, initialize an array of values.
var cmd = _.chunk(_.range(0, 300, 0), 30);
_.each(doses, function (dose, index) {
// these are "headers" to the machine language instructions.
cmd[index][0] = 1;
cmd[index][1] = dose.number;
// this generates the 28 commands to be executed.
// every four blocks together represents a single command
var commands = _.flatten(_.map(_.chunk(_.range(0, 28, 0), 4), function (day) {
_.each(dose.wellIndexes, function (well) {
day[well] = dose.count.value;
});
return day;
}));
});
(仍然是 WIP 代码)。
有了这个commands 数组,我想将它的值解压缩到cmd[index][2] 中,这样它将填充数组的其余部分。这可能吗?
查看文档,我找到了merging two arrays,但这不会替换索引后的值,只会追加到数组中。
如何在 javascript 中将数组值解压到另一个数组中?
【问题讨论】:
-
听起来
Array.slice是你想要的?
标签: javascript meteor underscore.js lodash