对象转数组

  • Post author:
  • Post category:其他


let obj= { 小明:17,小红:18,小黄:19 };
//预想转化成数组 [{name:'小明',age:17},{name:'小红',age:18},{name:'小黄',age:19}]


let ids = Object.keys(obj);
let newArr = [];
ids.forEach(function (value, key) {
newArr.push(
   {'name':value,'age':obj[value]})
})
console.log(newArr)



版权声明:本文为weixin_45376154原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。