map()函数
程序员文章站
2024-02-17 14:59:16
...
map():是指原数组中每个元素调用一个指定方法后的返回值组成的新数组,看官网上的代码解释
function fuzz(single){
var result=single.replace(/o/g,'e');
if(single=='kangaroo'){
result ='se';
}
return result;
}
var words=['foot','goose','moose',''kangaroo'];
console.log(words.map(fuzz));//['feet','geet','meese','kangareese'];
single.replace(/o/g,'e')的意思是全局的'o'都变成'e'
更多专业前端知识,请上【猿2048】www.mk2048.com