0
点赞
收藏
分享

微信扫一扫

js中map函数的使用

陈情雅雅 2022-02-25 阅读 64

js中map函数的使用

array.map(function(currentValue, index, arr), thisIndex)

currentValue:必须。当前元素的的值。
index:可选。当前元素的索引。
arr:可选。当前元素属于的数组对象。
thisValue:可选。对象作为该执行回调时使用,传递给函数,用作"this"的值。

案例1

 let arrnew = arrold.map(obj => {
    return obj.name;
 })

案例2

let songl=[];
      songl=res2.songlist.map(i=>{
        return {
          name:i.data.songname,
          name:i.data.songname,
        }
      })

案例3

let array = [1, 2, 3, 4, 5];
let newArray = array.map((item) => {
    return item * item;})
console.log(newArray)  // [1, 4, 9, 16, 25]
举报

相关推荐

0 条评论