I am try to convert a JavaScript array to an array of Object like
class Person {
name: string ="Test";
age: number = 23;
get Name(): string{
return this.name;
}
}
const getPerson =():Array<Person> =>{
var d:Array<Person> = [{"name": "Hugo", "age": 25},{"name": "Test", "age": 23}] as Person[];
return d;
}
console.log( getPerson()[0] instanceof Person)
console.log( getPerson()[0].Name)
console.log( getPerson()[1].Name)
But the output says, that the entries in the array are not instance of Person
[LOG]: false
[LOG]: undefined
[LOG]: undefined
I expect the output
[LOG]: true
[LOG]: Hugo
[LOG]: Test
Can someone explain why this is the case and what I have to change, that it works?