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

81
Visualizações
I´m unable to map elements of an array

Im trying to receive the data from my api into the charts at my website. Im stuck trying to fill my charts with the data, I have the code for filling the charts but when I map the JSON data and try to split the data into Date and temperature to put it in the chart it just does not work.

This is the code:

 var xmlhttp = new XMLHttpRequest();
var url = "http://localhost:8090/api/grafico/datos/temperatura/medicionAire/2059";
xmlhttp.open("GET", url, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
    if (this.readyState == 4 && this.status == 200) {
        var data = JSON.parse(this.responseText);
       //console.log(data);
        
        var dateG = data.map(function(elem) {
            return elem.fecha;
        });
        var temperatureG = data.map(function(elem) {
            return elem.temperatura;
        });

    }
}

I tried debuging it and it look like it does not recognize "fecha" or "temperatura" inside the array eventhough "elem" has the array in it: As you can see in this image, "elem" has the array in it, but "elem.fecha" is undefined and I dont know why. It should return me an array with only "fecha" of each line.

enter image description here

Log output of data:

[Array(4)]
0: Array(4)
0: {fecha: '2021-09-03T13:15:41.943Z', temperatura: 22.33}
1: {fecha: '2021-09-03T13:15:41.230Z', temperatura: 22.33}
2: {fecha: '2021-09-03T13:15:04.243Z', temperatura: 22.33}
3: {fecha: '2021-09-03T13:14:06.923Z', temperatura: 16.56}
length: 4
[[Prototype]]: Array(0)
length: 1
[[Prototype]]: Array(0)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I believe if you were to modify you code into something like so:

    var dateG = data.map(function(elem) {
        return elem.map(function(innerElem) {
            return innerElem.fecha
        });
    });

You would end up with dateG as 2D array of fetcha values.

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