+ 3
Object amount
Letās say I have an object... var food = {1: ābananaā, 2: āappleā,} How do I count the amount of food using only one line of code? Other languages example: #words #words will output 2
4 Answers
+ 3
Javascript object not like array, does not have a length property.
You need to get the keys array of the object, then only get the length of the keys array.
eg. console.log(Object.keys(food).length);
+ 2
I tried .length, and it caused an error.
+ 1
return food.length;
0
what error ? can you show me?