该函数可以对数组的所有元素进行操作,可以使用element和index两个参数。
const flavors = ["chocolate", "vanilla", "strawberry"];
const lengths = flavors.map(function(element, index){
console.log(element, index);
});
展开/折叠结果
chocolate 0
vanilla 1
strawberry 2
该函数可以对数组的所有元素进行操作,可以使用element和index两个参数。
const flavors = ["chocolate", "vanilla", "strawberry"];
const lengths = flavors.map(function(element, index){
console.log(element, index);
});
chocolate 0
vanilla 1
strawberry 2
发表评论