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 ]
原创文章,作者:745907710,如若转载,请注明出处:https://blog.ytso.com/267036.html