js处理数据?

let arr = [
    [
        {
            "orgName": "123456",
            "levelType": "0",
            "orgCode": "2365506"
        },
        {
            "orgName": "asdfasdf",
            "levelType": "0",
            "orgCode": "2380354"
        },
        {
            "orgName": "testet",
            "levelType": "0",
            "orgCode": "5165161"
        },
        {
            "orgName": "testet",
            "levelType": "0",
            "orgCode": "2380357"
        },
        {
            "orgName": "asdfasdf",
            "levelType": "0",
            "orgCode": "2380358"
        },
        {
            "orgName": "testetwet",
            "levelType": "0",
            "orgCode": "2380359"
        },
        {
            "orgName": "testetet",
            "levelType": "0",
            "orgCode": "2380360"
        },
        {
            "orgName": "阿斯顿",
            "levelType": "0",
            "orgCode": "2034440"
        },
        {
            "orgName": "标签测试2",
            "levelType": "0",
            "orgCode": "2366126"
        },
        {
            "orgName": "科勒厨卫有限公司javajava",
            "levelType": "0",
            "orgCode": "202029558"
        }
    ]
]

将每一层添加children:[],并将orgName改名为label

阅读 1.5k
3 个回答
arr[0] = arr[0].map(({orgName, ...v}) => ({...v, label: orgName, children: []}))
console.log(arr)
  let list = []
  for (let item of arr) {
    item = item.map(val => {
      val.label = val.orgName
      delete val.orgName
      return { ...val, children: [] }
    })
    list.push(item)
  }
推荐问题
宣传栏