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

163
Visualizações
Ambigous data type in javascript

[enter image description here][1]

I print a variable by console.log(TotalTime) and this is the result. It looks like an array but it's not. There are some other console.log commands: console.log(typeof TotalTime) => Object console.log(TotalTime[0]) => undefine i need to access the element shown in the picture but i couldn't. How can I get it? I need to calculate the sum of it. Here is my code:

getLightTimeUsing = async () => {
    const url = "";
    const devices = await axiosClient.get(url);
    var totalTime = [];

    devices.forEach(async (device) => {
      // console.log(device);
      if (device.description === "light") {
        let lightdevices = await this.getFeedData(device.key);
        lightdevices = [...lightdevices.reverse()];
        // console.log(lightdevices.length);
        lightdevices.forEach((ldevice, index, arr) => {
          if (index % 2 !== 1) {
            totalTime.push(
              Date.parse(arr[index + 1].created_at) -
                Date.parse(ldevice.created_at)
            );
          }
        });
      }
    });
    console.log(totalTime[0]) //=> undefine
    console.log(typeof totalTime) //=> object
    return totalTime;
  };
about 4 years ago · Juan Pablo Isaza
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