I have never worked with lists, object lists etc in Typescript and im not sure how they work. The below code doesnt do much except create a few objects and create some temp values for them through a loop, but i want the console log to print out the second objects name ("image1") followed by the second objects height (21).
What is wrong with the below code? Since undefined is being printed out.
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]);
}
}
this.images[1]is{name: "image1", height: 21}. Are you expecting the[0]after that to work like.name? Why?