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

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