如何在JS中转换这些数据

时间:2015-11-12 10:03:11

标签: javascript

X = Object {A: 33, B: 76, C: 1741}

Y = { 0:Object name: A value: 33 1:Object name: A value: 76 2:Object name: C value: 1741 }

如上所述,如何在JS中的多个对象上转换一个对象? X到Y.

1 个答案:

答案 0 :(得分:3)

var X = {A: 33, B: 76, C: 1741};
var Y = [];    
for (key in X) {
    Y.push({name: key, value: X[key]});
}