猿问

js for in 遍历问题

et obj ={"a":1,"b":2}


 let n = {};

 let m = [];

 for(let  i in obj){

   n.name = i;

  n.number =obj[i];

 }

 console.log(n) => {name: "b", number: 2},

 

 如何改进,让m 的结果是 [{name: "a", number: 1},{name: "b", number: 2}]


素胚勾勒不出你
浏览 475回答 1
1回答

达令说

let obj ={"a":1,"b":2}let m = [];for(let  i in obj){    m.push({name: i, number: obj[i]}) } console.log(m)
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答