Я называю мой API, который возвращает JSON в ответе.Я звоню как показано ниже:
getAllLearn() {
this.learnService.getAllLearn().subscribe(res =>{
// in result of log is I have res.featured which has only one index (0)
console.log(res);
this.myvar = res.featured;
})
}
Затем я добавляю этот код в конец:
this.myvar[1] = res.featured[0];
Затем в логе консоли я получаю 2 индекса (0,1).Почему это происходит?(Я знаю, что во встроенном console.log есть некоторые проблемы, но на самом деле не могу этого понять)
Наконец, мой код:
getAllLearn() {
this.learnService.getAllLearn().subscribe(res =>{
// ---- Now it contains two indexes in my res.featured -----
console.log(res);
this.featured2 = res.featured;
this.featured2[1] = res.featured[0];
})
}