+ 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 odpowiedzi
+ 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?