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

132
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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