I have an array. I want to dynamically generate new class instances from an array.
class Test{
constructor(name){
this.name = name;
}
getName(){
return this.name;
}
}
let myArray = [ "instance1", "instance2", "instance3" ];
I want a result like this:
let myArray[i] = new Test;
myArray[i].getName();
{}missing from constructor, for one). Look into Classes. Second value ofmyArryis not closed (with'). Did you want only elementiof the array to be an instance of the class, or all the elements of the array?