ES5 数组方法map
map() 方法返回一个由原数组中的每个元素调用一个指定方法后的返回值组成的新数组。
1、function fuzzyPlural(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(fuzzyPlural));
// ["feet", "geese", "meese", "kangareese"]
2、
var x = [1,2,3,4].map( function(item) { return item * 10; } ); // And now x is [10,20,30,40]

浙公网安备 33010602011771号