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

150
Vistas
searching trough object keys including numbers with for

I have a object that looks like this:

obj: {
centricAccountId1: number;
centricAccountId2: number;
...
centricAccountId10: number;
}

I'm writing a for loop to assign values to each key:

for (let i=1; i < 11 ;i++) {
    obj.centricAccountId${i} = //something
}

documentItem.centricAccountId${i} doesn't seem to work. how should I iterate through these keys without repeating their names ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You were close, but the code was wrong. You'll need to access the keys using square brackets and use template literals. You can try something like this

const obj =  {
centricAccountId1: 123,
centricAccountId2: 234,
centricAccountId3: 891
}

for (let i=1; i <= 3 ;i++) {
    obj[`centricAccountId${i}`] = obj[`centricAccountId${i}`]+1
}

console.log(obj)

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