Open zilongxuan001 opened 6 years ago
map可以遍历数组。
map
var oldArray = [1, 2, 3]; var timesFour = oldArray.map(function(val){ return val * 4; }); console.log(timesFour); // returns [4, 8, 12] console.log(oldArray); // returns [1, 2, 3]
map方法可以遍历数组的每个元素,创造一个新数组的值,但不会改变原数组。
Use the map function to add 3 to every value in the variable oldArray, and save the results into variable newArray. oldArray should not change.
var oldArray = [1,2,3,4,5]; // Only change code below this line. var newArray = oldArray.map(function(val){return val+3;});
https://www.freecodecamp.org/challenges/iterate-over-arrays-with-map
介绍
map
可以遍历数组。方法
map
方法可以遍历数组的每个元素,创造一个新数组的值,但不会改变原数组。练习
代码
结果显示
来源
https://www.freecodecamp.org/challenges/iterate-over-arrays-with-map