js数组对象转对象

将数组对象的数据转换为普通对象键值对key:value的形式

js数组对象转对象_第1张图片

let arr = [
    {id:'1',employeeNo:'110',name:'张三'},
    {id:'2',employeeNo:'111',name:'李四'},
    {id:'3',employeeNo:'112',name:'王五'},
    {id:'4',employeeNo:'113',name:'章雨'},
    {id:'5',employeeNo:'114',name:'小红'},
]
let newObj = {}
arr.map(item => {
  newObj[item.employeeNo] = item.name // 根据自己需求可以拼接
})
console.log(newObj) // {110: '张三', 111: '李四', 112: '王五', 113: '章雨', 114: '小红'}
console.log(newObj[112]) // '王五'

你可能感兴趣的:(js,前端,javascript)