javascript length of object
snippet in javascript

javascript object length

user3247

var size = Object.keys(myObj).length;

javascript length of object

user3236

var person={
    "first_name":"Harry",
    "last_name":"Potter",
    "age":14
};
var personSize = Object.keys(person).length; //gets number of properties (3) 

javascript object length

user2773

Object.size = function(obj) {
    var size = 0, key;
    for (key in obj) {
        if (obj.hasOwnProperty(key)) size++;
    }
    return size;
};

// Get the size of an object
var size = Object.size(myObj);

javascript object length

user1655

Using the Object.keys() method: The Object.keys() method is used to return the 
object property name as an array. The length property is used to get the number
of keys present in the object. It gives the length of the object.
Syntax:
objectLength = Object.keys(exampleObject).length