-4

I am trying to access the value. If I give {Movie.Score}, the score will print. In,

[{"score":0.70159364,"show":{"id":34653,"url":"https://www.tvmaze.com/shows/34653/all-american","name":"All American","type":"Scripted","language":"English",

I want to print names. I am using {movie.name} and {movie.score.name}, but it's not printing.

Michael M.
  • 10,486
  • 9
  • 18
  • 34
Kusuma Tn
  • 1
  • 1

2 Answers2

-1

Assumming that your array looks like this, you have to first tell your code which element in your array you want to access to so you write movie[index].show.name

If movie is your array then you have to acces each element by it's index.

and also movie.score.name won't work becuz name is not a property inside the score key

const movie = [{
    "score": 0.70159364,
    "show": {
      "id": 34653,
      "url": "https://www.tvmaze.com/shows/34653/all-american",
      "name": "All American",
      "type": "Scripted",
      "language": "English"
    }
}];

console.log(movie[0].show.name)
Chris G
  • 1,598
  • 1
  • 6
  • 18
-2

You can access by console.log('movie name ', this.item[0]['show']['name']);

Demo below. https://stackblitz.com/edit/angular-ja2m6n?file=src%2Fmain.ts

Stefani Toto
  • 280
  • 3
  • 13
  • you aware that you `console.log('movie name ', this.item[0]['name']);` returns undefined even in the link you provided right? – Chris G Mar 31 '23 at 17:33