数据格式转化

let data = {
  active: [1, 2, 3, 4, 5],
  disabled: [false, true, 3, 4, 5]
}

let final = []
let keys = Object.keys(data) // ['active', 'disabled']

let valueNum = data[keys[0]].length // 2

for(let j = 0; j < valueNum; j++) {
  let tempObj = {}
  // j = 1
  for (let k = 0; k < keys.length; k++) {
    let param = keys[k]
    let tempValue = data[param]
    tempObj[param] = tempValue[j]
  }
  final.push(tempObj)
}
console.log(final)

  

 

posted on 2018-09-29 16:40  木之子梦之蝶  阅读(141)  评论(0编辑  收藏  举报

导航