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

392
Views
How to push json data into an array using d3.json()?

I'm trying to insert the elements from this dataset: https://raw.githubusercontent.com/freeCodeCamp/ProjectReferenceData/master/GDP-data.json

into an array. But after the code, when I console.log(arr), the array is still empty.

The console.log inside the for actually works and prints the array, but arr.push doesnt. Why?

  let url = "data.json";
  var arr = [];
  d3.json(url).then(data => {
    for(let i = 0; i < data.data.length; i++) { 
         arr.push(data.data[i]); 
         console.log(data.data[i]);
     }
 })

 console.log(arr);
        <script src="https://d3js.org/d3.v6.min.js"></script>

about 4 years ago · Juan Pablo Isaza
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!