Anjan Dutta

Get length of object javascript

Get length of object javascript

The optimal way of determining an object’s length in Javascript is to use the Object.keys() method. This method returns an array containing all enumerable properties of an object.

Then we will use .length property to get the length of that array and it will return the correct length.

See below example:

let person = {name: 'John', age: 30, address: '18/1, Dover lane' };
var size = Object.keys(person).length;