I’m working out of a text book JavaScript All-In_One. I’m following the directions to write an array. I’m using vscode. This is my array:
const list = new Products['eggs','milk','cheese','garlic','onion','kale','salt','pepper'];
When I run visual studio I get the error. Products not defined.
I tried declaring the array before assigning it. When I run the code I expect to get the list in the array. When I write Products.length I expect to get the length of the array characters. I tried using the console in the browser and I get the same error.
2
Answers
If the
Products
constructor accepts an array argument:The syntax for instantiating a class is:
new <class_name>(arg1, arg2, ...);
It looks like you were trying to do: