I have a JavaScript object like
var obj = { key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' }
How can I get the length and list of keys in this object?
var obj = { key1: 'value1', key2: 'value2', key3: 'value3', key4: 'value4' } var keys = Object.keys(obj); console.log('obj contains ' + keys.length + ' keys: '+ keys);
2.1m questions
2.1m answers
60 comments
57.0k users