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

131
Views
how to bind a name value to a for loop using moment-timezone

I have a list of time zones that has been populated as a query as follows:

async load(){
    this.usertimezones = await this.query(gets my query result)
}

This is what the usertimezones looks like:

0: {userId: '0b8502d0-0b65-4092-bc4e-5c491acc7771', timezone: 'Africa/Bamako', isActive: true, id: '69c6051b-5b8b-43cf-b771-7884b6eb5c01'}
1: {userId: '0b8502d0-0b65-4092-bc4e-5c491acc7771', timezone: 'America/Araguaina', isActive: true, id: 'b609808d-3002-422a-810c-8d3e17c972bc'}

For each timezone, I pass it as follows:

    async load(){
        this.usertimezones = await this.query(gets my query result)
        this.usertimezones.forEach(x => {
            let test = Mo().tz(x.timezone).format('MMMM Do YYYY, h:mm a');
            console.log(test);
        })
    }

And then the output is as follows:

March 15th 2022, 7:53 pm
March 15th 2022, 4:53 pm

However, now I can't tell which timezone each result belongs to. How do I add the timezone name to it, and push it to an array, so it looks like this?

Africa/Bamako March 15th 2022, 7:53 pm
America/Araguaina March 15th 2022, 4:53 pm
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can re-use x.timezone in your forEach function. Like so:

const result = [];
this.usertimezones.forEach(x => {
    const time = Mo().tz(x.timezone).format('MMMM Do YYYY, h:mm a');
    const str = x.timezone + ' ' + test;
    console.log(str);
    result.push(str);
})

The above code will log out the desired output, as well as pushing it into the result array.

about 4 years ago · Juan Pablo Isaza Report
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!