Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda