在 Javascript 中将函数应用于数组的每个值
var numbers = [1,2,3,4,5];
var squares = numbers.map(function(x) {
return x*x;
});
// squares is [1,4,9,16,25]
var numbers = [1,2,3,4,5];
var squares = numbers.map(function(x) {
return x*x;
});
// squares is [1,4,9,16,25]