js object length
snippet in javascript

javascript object length

user8868

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

js object length

user7514

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

javascript object length

user4030

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

user7518

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