给定一个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"}]
var dataArray = []; for(var o in dataObject) { dataArray.push(dataObject[o]); }