Array
University of Oregon

Object.keys

Object.keys() returns an array whose elements are strings corresponding to the enumerable properties found directly upon object. The ordering of the properties is the same as that given by looping over the properties of the object manually (e.g., with a loop).

Since it returns an array, you can use the forEach method to list the properties:

var person = {
    firstName: 'Argus',
    lastName: 'Filch',
    // ...
};

Object.keys(person).forEach(function(prop) {
    console.log('Person ', prop,': ', person[prop]);
});

//You do not need to build the output using + for string concatenation. //You can simply use comma, as console accepts any number of arguments.

console.log('I can accept',' any ', 'number', 'of ', 'arguments!');
Skip to toolbar