好吧,所以我坚持使用代码阅读文档。
我从JS开始,所以轻松一个我=]。
我有和阵列cal Area
其中包含很少的参数
let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights", ...];
我无法更改此数组,直到我的代码的特定部分被执行但在我希望向每个位置添加另一个值之后。我怎么做才能得到这样的表现:
let Area = ["Kanig Village 14:30", "Fort Chune 15:30", "Shadowy Heights 16:30", ...];
答案 0 :(得分:1)
我希望这是你的答案
let Area = ["Kanig Village", "Fort Chune", "Shadowy Heights"];
for(i=0;i<Area.length;i++)
{
var hour=14+i;
Area[i]+=" "+hour+" : 30";
}
答案 1 :(得分:1)
我认为这就是你想要做的事情:
https://jsfiddle.net/wxzrpjeL/
//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());