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

227
Vistas
Updating an Array that's present inside an Object

I'm trying to update an array (Array name is "Variables" please refer the attached screenshot) which presents inside an Object, so I want to update that array if there is word called "placeholder" in alertMessage(it's a different property presents in the same Object)

I'd appreciate any help on how to update this array in question, I tried using pop method but it didn't go as planned and I've attached screenshots of the Objects for reference

enter image description here

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

You can retrieve the string placeholder like this data['alertMessage']['en_US']['all'] and then use a conditional statement to make changes to the array inside the data object.

let data = {
  alertOne: '',
  alertTwo: '',
  alertMessage: {
    en_US: {all: 'placeholder'}
  },
  variables: [
     {id: 0, uuid: '123'},
     {id: 1, uuid: '223'},
     {id: 2, uuid: '323'}
  ]
}

let all = data['alertMessage']['en_US']['all']

// if condition is met add a new object to the array
if(all === 'placeholder'){
  data.variables = [...data.variables, {id: 3, uuid: '423'}] 
}

console.log(data)

about 4 years ago · Santiago Gelvez 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