1var person={
2 "first_name":"Harry",
3 "last_name":"Potter",
4 "age":14
5};
6var personSize = Object.keys(person).length; //gets number of properties (3)
1//length of this object is 4
2let object = {
3 'A':{
4 '10':['a','b','c']
5 },
6 'B':{
7 '20':['a','b','c']
8 },
9 'C':{
10 '30':['a','b','c']
11 },
12 'D':{
13 '40':['a','b','c']
14 },
15}
16
17//Get the keys of the object (A,B,C,D) and print how many there are
18Object.keys().length
19> prints: 4
20
1Object.size = function(obj) {
2 var size = 0,
3 key;
4 for (key in obj) {
5 if (obj.hasOwnProperty(key)) size++;
6 }
7 return size;
8};
9
10// Get the size of an object
11const myObj = {}
12var size = Object.size(myObj);