- I run the code but find that I have to use cal[item] to put the item in array inside the object. Why the old ways cal.item doesn't work?
- I tried using "if + else" like below and using "if" only, the result are different, the "if" version gives me the correct answer. But I don't see why it causes different flow in calculation.
Thank you for your help in advance.
const number = "3 5 30 31 43 48 2 11 13 45 46 49 11 14 21 28 37 44 18 29 32 33 36 40 2 20 24 30 32 46 5 17 35 37 42 49 1 24 25 27 31 37 15 17 29 30 34 37 5 10 18 20 28 33 1 22 25 27 31 36"
const array = number.split(" ")
const cal = {}
for (const item of array){
if(cal.item == null){
cal.item = 0
}else{
cal.item += 1;
}
}
console.log(cal)