Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (7k points)

How to get length and list of keys in JavaScript?

1 Answer

0 votes
by (13.1k points)

You try something like this:

var obj = {

  key1: 'value1',

  key2: 'value2',

  key3: 'value3',

  key4: 'value4'

};

var keys = [];

for (var k in obj) keys.push(k);

console.log("total " + keys.length + " keys: " + keys);

Interested in full-stack development? Check out the full-stack developer course from Intellipaat. 

Related questions

0 votes
1 answer
0 votes
1 answer
asked Mar 2, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...