Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

239
Vistas
How to fix this error : Cannot read properties of undefined (reading 'length') in Javascript

I am new to Javascript. Why is this code giving me the error: Cannot read properties of undefined (reading 'length')? I have tried to add the datasrc code before but it is not working. Does anyone else have an idea on how to fix it?

//implement css in this files
import './style.css';

//jquery already imported
import $ from 'jquery';
// ajax to load

// do table data binding here using data from variable resultArr
var myArray = []

$.ajax({
    method:'GET',
    url:'https://www.seetrustudio.com/data.php',
    success:function(response){
        myArray = response.data
        buildTable(myArray)
        console.log(myArray)
    }
})
function buildTable(data){
    var table = document.getElementById('myTable')

    for (var i = 0; i < data.length; i++){
        var row = `<tr>
                        <td>${data[i].date}</td>
                        <td>${data[i].weather}</td>
                        <td>${data[i].temperature}</td>
                        <td>${data[i].temp_unit}</td>
                  </tr>`
        table.innerHTML += row


    }
}`
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

There is the only one place in your code where length is used: data.length in for loop.

for (var i = 0; i < data.length; i++){

So, intepreter tells I cannot read length of undefined hence data is undefined, hence myArray and response.data is undefined and you should set a breakpoint on line

myArray = response.data

and see what is in the response, and why it's not contains the key data.

about 4 years ago · Juan Pablo Isaza Denunciar

0

For me, I have not updated the API key for my app. When I have done so, The issue is resolved.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda