Skip to main content Accessibility Feedback

Objects

Object.keys()

Return an array of keys from an object. Pass in the object as an argument.

var lunch = {
	sandwich: 'turkey',
	chips: 'cape cod',
	drink: 'soda'
};

// logs ['sandwich', 'chips', 'drink']
var keys = Object.keys(lunch);
console.log(keys);

Works in all modern browsers, and IE9+. You can extend support back further with polyfills.