Array.prototype.map()
作者:互联网
Array.prototype.map()
遍历加工,不改变原数组,与foreach相似,但优于foreach
- 模仿foreach的用法
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
words.map(item => {
console.log(item);
});
- 一般用法
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
let a = words.map(item => {
return 1
});
console.log(a); //[ 1, 1, 1, 1, 1, 1 ]
标签:map,console,item,foreach,words,exuberant,Array,prototype 来源: https://www.cnblogs.com/zhumenglong/p/16371957.html