Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
How to extract something out of a JSON object and display it in the DOM

I keep getting undefined in the DOM...

I am trying to extract the city and state from this and display it in the DOM.

{
 "post code": "90210", 
 "country": "United States", 
 "country abbreviation": "US", 
 "places": [
     {"place name": "Beverly Hills", 
      "longitude": "-118.4065", 
      "state": "California", 
      "state abbreviation": "CA", 
      "latitude": "34.0901"}
  ]
}
var data = JSON.parse(ajax.responseText);
                //var str = '';
                var boo = '';
                //str =  data[1];
                boo +=  data.state;
                //document.getElementById('city').innerText = str;
                document.getElementById('state').innerHTML = boo;
            } else { // Status error!
                //document.getElementById('city').innerHTML = ajax.statusText;
                document.getElementById('state').innerHTML = ajax.statusText;
            }       

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It looks like that 'state' field is nested in another object which is nested inside of an array, so the correct way to access it would be

data.places[0].state
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!