编程语言
首页 > 编程语言> > javaScript数组对象取出某一列

javaScript数组对象取出某一列

作者:互联网

1、数组

1.1、需求

[ {id:3,name:'张三'}, {id:4,name:'李四'}, {id:5,name:'王五'}]

取出name列,并成新数组

['张三', '李四', '王五']

1.2、map

let arr = [ {id:3,name:'张三'},  {id:4,name:'李四'}, {id:5,name:'王五'}]
let arr2 = arr.map(v => {return v.name})

console.dir(arr2)
/*
    Array(3)
    0: "张三"
    1: "李四"
    2: "王五"
    length: 3
*/

标签:张三,name,javaScript,李四,一列,数组,王五,id
来源: https://www.cnblogs.com/pine007/p/16363374.html