length of an object in javascript
var person={
"first_name":"Harry",
"last_name":"Potter",
"age":14
};
var personSize = Object.keys(person).length; //gets number of properties (3) 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);//length of this object is 4
let object = {
'A':{
'10':['a','b','c']
},
'B':{
'20':['a','b','c']
},
'C':{
'30':['a','b','c']
},
'D':{
'40':['a','b','c']
},
}
//Get the keys of the object (A,B,C,D) and print how many there are
Object.keys().length
> prints: 4
Also in JavaScript:
- self invoking function javascript es6
- await async sleep
- regular expression search for any character until Space
- javascript var vs let
- javascript 2 decimal float array elements
- model mongoose
- http requests in vue 3
- javascript append list
- jquery add remove class clicked element
- change version node centos
- rematch config
- join method in express
- how to add script before </body> in magento 2
- error Unexpected end of JSON input while parsing near '...
- how to return character associated to character code javascript
- como ler um arquivo json com javascript
- javascript string interpolation
- dark mode with react hooks
- GET http://localhost:8000/js/app.js net::ERR_ABORTED 404 (Not Found) in laravel 6
- vuejs take rgba values from coordinate
- kotlin jsonobject from string
- number to array js
- canvas cut path to image
- grpc node