0

i have an ajax form and the response data is this json

[{"runtime":"142 min" , "title":"blabla"}]

but when i see it from chrome developer tools it is like this

[Object]
0: Object
runtime: "142 min"
title: "blabla"
__proto__: Object
length: 1
__proto__: Array[0]

if i want to set one of the keys to a var what should i do

i tried var x = data.runtime ; but it isnt working

i tried var x = data.0.runtime ; and it makes a syntax error

1 Answer 1

5

Note the square brackets around your JSON data - it's not an object, but an array, containing one value - your object.

To access that object, access the first value in the array: data[0].runtime.

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.