-1

I have the following JSON value pushed from the server.

         result=[{"id":1492,"name":"Delhi"},
                 {"id":109,"name":"Coimbatore"},
                 {"id":576,"name":"Konni"},
                 {"id":525,"name":"Kottayam"}
                ]

I know how to convert JSON Array to Javascript Array.Here is the code below(got from stackoverflow)

        var locations = [];
        $.each(result, function(i, obj) {
            locations.push([obj.id,obj.name]);
        });

I want to convert this JSON Array to a JavaScript Object Array so that I can access the values as jarray[0].id which will give me the value 1492. Please advice

1
  • 3
    That's not a JSON array. It's a JavaScript array. JSON is a method of storing data as text. Commented Sep 12, 2012 at 14:36

1 Answer 1

3

You don't need to do anything to the result array. Just use result[0].id and it will evaluate to 1492.

1
  • Thank you. I believe I have to read the core javascript well again Commented Sep 12, 2012 at 17:14

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.