I am very new to JavaScript, and I tried to add array to my class to save some data:
class ListOfItems {
let listOfItems = []
addItem(item) {
listOfItems.push(item);
console.log(listOfItems);
}
}
const lOi = new ListOfItems();
lOi.addItem(10);
But I get this error:
SyntaxError: Unexpected identifier
I don't know if it is allowed to have variables in class. What can I do? I just want to have array of every added item.
letis needed? Remove thelet, then it can be accessed bythis.listOfItemsthis.listOfItems = []inside of that.