我想将combinationsFormController
中每个对象的名称(7,8,9)放入数组中。
图片来自Firebug。
答案 0 :(得分:1)
像这样,example here:
var combinationsFormController = {
prop1: {'prop1':7},
prop2: {'prop2':8},
prop3: {'prop2':9},
1: {'prop1':7},
2: {'prop2':8},
3: {'prop2':9},
7: {'prop1':7},
8: {'prop2':8},
9: {'prop2':9},
};
var arrProps=[];
for ( property in combinationsFormController ) {
if (combinationsFormController.hasOwnProperty(property))
{
console.log( property );
arrProps.push(property)
}
}
答案 1 :(得分:1)
在现代浏览器中,可以使用Object.keys()
创建数组
var arr = Object.keys(combinationsFormController);
对于像IE< 9这样的旧浏览器,包括polyfill found in MDN Docs