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

237
Vistas
How can I change the name of the key in an object using "for ... in"

I want to use the for in function to change the keys. I know I could do it with map but can it be done with for in?

 const meinObject = {
        name: "Dominic",
        plz: 9548,
    };

    for (let key in meinObject) {
        key + "1" + meinObject[key]
        console.log(key);
    }
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Ok, so what you can do is assign the value of your key to a new key, then delete the old key. This does not use a for in loop, it is something simpler.

obj['newKey'] = obj['oldKey'];
delete obj['oldKey'];

or in your case

meinObject['key'] = meinObject['newKey']
delete meinObject['key']
about 4 years ago · Juan Pablo Isaza Denunciar

0

const meinObject = { name: "Dominic", plz: 9548, }; for (let key in meinObject) { key + "1" + meinObject[key] // this does not make sense var value = meinObject[key]; // get dominic, then plz etc. console.log('original', key, value); meinObject[key] = 'overwrite!!!'; var value = meinObject[key]; // get dominic, then plz etc. console.log('altered', key, value); } console.log('object after modification', meinObject);

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