【发布时间】:2020-06-26 11:52:21
【问题描述】:
我有两个数组:
1) listArray 格式如下:
0: {value: "373", text: "1 - First Item in the Array"}
1: {value: "343", text: "2 - Second Item in the Array"}
2: {value: "376", text: "3 - Third Item in the Array"}
2) displayArray 格式如下:
0: {name: "Number One", position: "373", additionalinfo: "Description Goes Here"}
1: {name: "Number Two", position: "343", additionalinfo: "Description Goes Here"}
2: {name: "Number three", position: "376", additionalinfo: "Description Goes Here"}
我想让第二个数组 displayArray 使用来自 listArray 的信息看起来像这样:
0: {name: "Number One", position: "1 - First Item in the Array", additionalinfo: "Description Goes Here"}
1: {name: "Number Two", position: "2 - Second Item in the Array", additionalinfo: "Description Goes Here"}
2: {name: "Number three", position: "3 - Third Item in the Array", additionalinfo: "Description Goes Here"}
我不介意创建第三个数组,但是当我尝试在 array.push 中使用它时,出现错误。我该怎么做?
【问题讨论】:
-
您尝试过什么,遇到了什么错误?
forEach或map应该这样做。 -
如何有条件地从数组 1 获取数据并替换数组 2?
-
这不是错误,而是通过将数组 2 中的位置值替换为数组 1 中的文本值,它不起作用
标签: javascript arrays vue.js