skip to Main Content

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.

2

Answers


  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)
    Login or Signup to reply.
  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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search