Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!