I am new to using lists and object lists in Typescript and I'm unsure of how they function. In the code snippet below, a few objects are created and some temporary values are assigned to them through a loop. However, my goal is to have the console log display the name of the second object ("image1") followed by its height (21).
There seems to be an issue with the code below as it prints out "undefined".
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
image = {};
images = [this.image];
constructor() {
}
ngOnInit() {
for (let i = 0; i < 3; i++) {
this.image = {name: "image"+i, height: 20+i};
this.images[i] = this.image;
}
console.log(this.images[1][0]);
console.log(this.images[1][1]);
}
}