小编典典

如何将JavaScript对象的属性值提取到数组中?

javascript

给定一个JavaScript对象:

var dataObject = {
   object1: {id: 1, name: "Fred"}, 
   object2: {id: 2, name: "Wilma"}, 
   object3: {id: 3, name: "Pebbles"}
};

如何有效地将内部对象提取到数组中? 我不需要维护 object [n] ID 的句柄。

var dataArray = [
    {id: 1, name: "Fred"}, 
    {id: 2, name: "Wilma"}, 
    {id: 3, name: "Pebbles"}]

阅读 265

收藏
2020-05-01

共1个答案

小编典典

var dataArray = [];
for(var o in dataObject) {
    dataArray.push(dataObject[o]);
}
2020-05-01