0 votes
1 view
in Web Technology by (32.5k points)

If I have a JavaScript object, say

var myObject = new Object(); 

myObject["firstname"] = "Gareth"; 

myObject["lastname"] = "Simpson"; 

myObject["age"] = 21;

is there a built-in or accepted best practice way to get the length of this object?

1 Answer

0 votes
by (76.8k points)

The best way to get the length of this object is to use the below-mentioned way:-

Object.keys(myArray).length

...