how extract keys from object js code example
Example 1: javascript foreach object keys
var lunch = {
sandwich: 'ham',
snack: 'chips',
drink: 'soda',
desert: 'cookie',
guests: 3,
alcohol: false,
};
Object.keys(lunch).forEach(function (item) {
console.log(item); // key
console.log(lunch[item]); // value
});
// returns "sandwich", "ham", "snack", "chips", "drink", "soda", "desert", "cookie", "guests", 3, "alcohol", false
Example 2: longitud objeto javascript
let unorderedData = {
real_name: 'Millie Bobby Brown',
character_name: 'Eleven',
series: 'Stranger Things'
};
console.log(Object.keys(unorderedData).length)