Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

136
Vistas
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>

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.