Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/409.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 替换VueJs数组中的值_Javascript_Arrays_Vue.js - Fatal编程技术网

Javascript 替换VueJs数组中的值

Javascript 替换VueJs数组中的值,javascript,arrays,vue.js,Javascript,Arrays,Vue.js,我有两个阵列: 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"} 0: {name: "Number One", position: "373", additionalinfo:

我有两个阵列:

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"}
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"}
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"}
2)
displayArray
格式如下:

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"}
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"}
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"}
我希望第二个数组
displayArray
使用
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"}
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"}
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"}
我不介意创建第三个数组,但当我试图在
数组中使用它时,我遇到了错误。我该怎么做?

选项1:更改
displayArray
使用forEach的

displayArray.forEach((项目,索引)=>{
item.position=listArray[index].text;
})
选项2:创建新阵列 使用
映射

const newArray=displayArray.map((项目,索引)=>{
const newitem=Object.assign({},item);
newitem.position=listArray[index].text;
返回新项目;
})

下面是一个

您尝试了什么,出现了哪些错误?一个
forEach
map
应该可以做到这一点。从数组1获取数据并替换数组2会是一个什么样的条件呢?这不是一个错误,而是用数组1的文本值替换数组2的位置值不起作用