javascript - Get array of object's keys -
i keys of javascript object array, either in jquery or pure javascript.
is there less verbose way this?
var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' }; var keys = []; (var key in foo) { keys.push(key); }
var foo = { 'alpha' : 'puffin', 'beta' : 'beagle' }; var keys = object.keys(foo); // ['alpha', 'beta'] // (or maybe other order, keys unordered).
use object.keys
.
this es5 feature. means works in modern browsers will not work in legacy browsers.
the es5-shim has implementation of object.keys
can steal
Comments
Post a Comment