I would like to get the keys of a JavaScript object as an array, either in jQuery or pure JavaScript.(我想以jQuery或纯JavaScript的形式获取JavaScript对象的键作为数组。)
Is there a less verbose way than this?(有没有比这更详细的方法?)
var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' };
var keys = [];
for (var key in foo) {
keys.push(key);
}
ask by Richard translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…