Długość obiektu JavaScript
var size = Object.keys(myObj).length;
Crowded Caiman
var size = Object.keys(myObj).length;
var person={
"first_name":"Harry",
"last_name":"Potter",
"age":14
};
var personSize = Object.keys(person).length; //gets number of properties (3)
const objLen = Object.keys(myObj).length;
//var size = Object.keys(myObj).length;
let object = {
user:"hello",
password:"123"
}
console.log(Object.keys(object).length)
> prints: 2
Object.keys(myArray).length
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
const myObj = {}
var size = Object.size(myObj);