0

I have a variable that returns a nested object,

console.log (moviesTrailer)

Returns,

[Object]
  0: Object
    backdrop: "/LvmmDZxkTDqp0DX7mUo621ahdX.jpg"
    cast: null
    created_at: "2016-01-08T17:21:32.112Z"
    crew: null
    id: 35
    image: "/bIuOWTtyFPjsFDevqvF3QrD1aun.jpg"
    movie_id: "10195"
    release_date: "2011-04-28"
    title: "Thor"
    updated_at: "2016-01-08T17:21:32.112Z"
    user_id: null
    __proto__: Objectlength: 1
    __proto__: Array[0]

How can I reach data such as id, or title?

I've tried

console.log (moviesTrailer.object[0].id)

and

console.log (moviesTrailer.data[0].id)

but this returns a TypeError: Cannot read property '0' of undefined.

2
  • moviestrailer is returning an array of objects, denoted by [Object]. You have to reference the index first Commented Jan 8, 2016 at 17:40
  • @corvid imo no. moviesTrailer is an object with a property called 0, instead of an array with index 0. Commented Jan 8, 2016 at 17:42

1 Answer 1

1

moviesTrailer[0].id should work.

moviesTrailer is an object with a property named 0 with a value of a reference to an object with these properties:

backdrop: "/LvmmDZxkTDqp0DX7mUo621ahdX.jpg"
cast: null
created_at: "2016-01-08T17:21:32.112Z"
crew: null
id: 35
image: "/bIuOWTtyFPjsFDevqvF3QrD1aun.jpg"
movie_id: "10195"
release_date: "2011-04-28"
title: "Thor"
updated_at: "2016-01-08T17:21:32.112Z"
user_id: null
__proto__: Objectlength: 1
__proto__: Array[0]

demo here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.