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

102
Vistas
Changing properties in JSON data

how can I change the "ABC" field in the code below?

 var data = {ABC:{key:'dynamic_key',value:'dynamic_value'}}

Normally, I can give the value I want by saying data.ABC.key, but what I really want is to go as data.CCC instead of data.ABC, so I just want to change the ABC name.

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

0

Re-assign the inner object to the new outer object key, then delete the previous.

 var data = {ABC:{key:'dynamic_key',value:'dynamic_value'}}
 
 data.CCC = {...data.ABC}
 delete data.ABC
 
 console.log(data)


That also could be (without using delete)

var data = {ABC:{key:'dynamic_key',value:'dynamic_value'}}

data = {CCC: data.ABC}
console.log(data)


EDIT... It you want to use a string from a variable to set the new key, use the bracket notation:

var data = {ABC:{key:'dynamic_key',value:'dynamic_value'}}
var newKey="CAR"

data[newKey] = data.ABC
delete data.ABC
console.log(data)

about 4 years ago · Juan Pablo Isaza Denunciar

0

data.CCC = data.ABC // on object create new key name. Assign old value to this

delete data.ABC //delete object with old key name

output:

{ 
  "CCC":
    {
       "key": "dynamic_key",
       "value": "dynamic_value"
    }
}
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