Javascript: Call method on object in array of objects

Viewed 6230

I created a class with a method:

class MyClass{

myMethod(){
    return ...;
}}

After that I push every instance of that class to an array:

let myList = [];
myList.push(myClass)

How can I call myMethod() within a loop? This code fails:

for (var i = 0; myList.length; i++) {
    myList[i].myMethod();
}

Uncaught TypeError: Cannot read property 'myMethod' of undefined

Thx, piccus

2 Answers
Related