Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/407.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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 JS-阵列(将2个阵列融合为一个)_Javascript_Arrays - Fatal编程技术网

Javascript JS-阵列(将2个阵列融合为一个)

Javascript JS-阵列(将2个阵列融合为一个),javascript,arrays,Javascript,Arrays,好吧,我继续读代码文档。 我从JS开始,所以简单一点我=]。 我已经得到并调用了数组dArea 其中包含很少的参数 let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights", ...]; 在执行代码的特定部分之前,我无法更改此数组,但在我希望向每个位置添加另一个值之后。我该如何做到这一点,才能得到这样的结果: let Area = ["Kanig Village 14:30", "Fort Chune 15:30", "Shado

好吧,我继续读代码文档。 我从JS开始,所以简单一点我=]。 我已经得到并调用了数组d
Area
其中包含很少的参数

let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights", ...];
在执行代码的特定部分之前,我无法更改此数组,但在我希望向每个位置添加另一个值之后。我该如何做到这一点,才能得到这样的结果:

let Area = ["Kanig Village 14:30", "Fort Chune 15:30", "Shadowy Heights 16:30", ...];

我希望这是你的答案

let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights"];
for(i=0;i<Area.length;i++)
  {
    var hour=14+i;
    Area[i]+=" "+hour+" : 30";
  }
let Area=[“卡尼格村”、“春恩堡”、“阴影高地”];

对于(i=0;i我认为这就是你想要做的:


你尝试过什么?你从哪里得到新的值?当心。声明你的变量。:-(披露:这是我贫血小博客上的一篇文章。)
//Declare 2 arrays
let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights"];
let b = ["1", "2", "3"];

//Execute a function for each element in the Area array
Area.forEach(function(val, i) {
//The function appends a space, and the corresponding element in the second array
      Area[i] += " " + b[i];
});

// just to illustrate the result, throw the result to the screen as a string...
alert(Area.toString());