Objects don't have the property
length
to find their length.
Let's make sure of this. Let's have
the following object:
let obj = {a: 1, b: 2, c: 3};
Let's try to find out the number of its elements:
console.log(obj.length); // shows undefined
Let's solve the task in a roundabout way - we get an array of object keys and find its length:
console.log(Object.keys(obj).length); // shows 3
Find the number of elements in the following object:
let obj = {x: 1, y: 2, z: 3};