I have this code that fails when I try to use the for loop
class TestA {
testArray = [];
constructor() {
this.testArray.push({
name: "joe",
age: 70
});
this.testArray.push({
name: "mike",
age: 50
});
this.testArray.push({
name: "bob",
age: 33
});
}
testLoop() {
for (test of this.testArray) {
console.log(" >>> " + test.name + " " + test.age);
}
}
}
var a = new TestA();
a.testLoop();
The error:
Uncaught ReferenceError: test is not defined
I can get away with that by using different kind of loop but don't understand why that doesn't work?