当前位置:网站首页>JS array object to object

JS array object to object

2022-06-25 01:44:00 Э Time walker to me

Convert the data of an array object into a normal object key value pair key:value In the form of

js

let arr = [
    {
    id:'1',employeeNo:'110',name:' Zhang San '},
    {
    id:'2',employeeNo:'111',name:' Li Si '},
    {
    id:'3',employeeNo:'112',name:' Wang Wu '},
    {
    id:'4',employeeNo:'113',name:' Zhang Yu '},
    {
    id:'5',employeeNo:'114',name:' Xiaohong '},
]
let newObj = {
    }
arr.map(item => {
    
  newObj[item.employeeNo] = item.name //  It can be spliced according to your own needs 
})
console.log(newObj) // {110: ' Zhang San ', 111: ' Li Si ', 112: ' Wang Wu ', 113: ' Zhang Yu ', 114: ' Xiaohong '}
console.log(newObj[112]) // ' Wang Wu '
原网站

版权声明
本文为[Э Time walker to me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206242107143133.html