为什么array.map不起作用?
我的代码是:
let myArray = [000,111,222,333,444,555,666,777,888,999];
myArray.map((value) => {
return = 1000 - value;
});
console.log(myArray);
结果是: [0,111,222,333,444,555,666,777,888,999]
答案 0 :(得分:3)
调用map
返回一个新数组。它不会在原位置修改旧的。改为这样做:
let myArray = [000,111,222,333,444,555,666,777,888,999];
let myNewArray = myArray.map((value) => {
return 1000 - value;
});
console.log(myNewArray);