0

I have a JSON object that when I do this:

console.log(response.json);

I get this

{ results:
   [ { address_components: [Object],
       formatted_address: 'Google Bldg 42, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA',
       geometry: [Object],
       place_id: 'ChIJPzxqWQK6j4AR3OFRJ6LMaKo',
       types: [Object] } ],
  status: 'OK' }

I want to be able to select formated_address as an example. I've tried variations of console.log(response.json.formatted_address); that but I can't quite figure it out.

0

4 Answers 4

1

You have an object inside an array, so you need to specify the first item in the array.

response.json.results[0].formatted_address

should work.

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

Comments

1

Just access the first element , i.e index 0 of the array and then formatted_address

console.log(response.json.result[0].formatted_address);

Comments

0

The value is not accessible directly so you need to do something like this.Your formatted_address lies in an array which is present in the result key.So to get your result do something like this

console.log(response.json.result[0].formatted_address);

Comments

0

you can use this code

console.log(response.json.results[0].formatted_address);

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.