我有两个数组[14, 20 , 40 , 40]
和["6:28 PM","7:28 PM","8:28 PM","9:28 PM"]
。
我想要这个
[{x:14,y:"6:28 PM"},
{x:20,y:"7:28 PM"},
{x:40,y:"8:28 PM"},
{x:40,y:"9:28 PM"}]
我试图用另一个数组(如
a.push(x:values,y:time)
)推入数组,但这无法解决。 最佳答案
const ids = [14, 20 , 40 , 40];
const times = ["6:28 PM","7:28 PM","8:28 PM","9:28 PM"];
const result = ids.map((id, i) => ({ x: id, y: times[i] }));
console.log(result);
与Angular无关。
关于javascript - 用键值存储数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54709006/