【发布时间】:2018-06-13 12:27:24
【问题描述】:
我有一个对象如下:
const data = [
{name: 'Week 1', owner: 0, others: 4, amt: 4},
{name: 'Week 2', owner: 0, others: 7, amt: 7},
{name: 'Week 3', owner: 0, others: 10, amt: 10},
{name: 'Week 4', owner: 0, others: 12, amt: 12},
{name: 'Week 5', owner: 0, others: 3, amt: 3},
{name: 'Week 6', owner: 0, others: 0, amt: 0},
{name: 'Week 7', owner: 0, others: 9, amt: 9},
];
我有两个数组,即:
var arrayOwner = [0,0,0,0,0,0,0];
var arrayOthers = [2,4,3,6,3,8,9];
问题是我必须取每个数组的第一个值(arrayOwner 和arrayOthers),然后更新数据数组中的第一个对象。
例如,对于第 1 周,将采用来自 arrayOwner 的 0 和来自 arrayOthers 的 2,然后在数据数组的第一个对象中更新。
【问题讨论】:
标签: javascript arrays dictionary data-structures