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

88
Vistas
Spread operator to update array of objects

I have an array of objects. In that array, I want to update a single object, and in that object, I want to update only specific properties. I tried:

setRequiredFields(prevRequiredFields => ([
            ...prevRequiredFields, prevRequiredFields.find(x => x.name = field) ?  {
                isValid: isValid,
                content: content,
                isUnchanged: false
            }
]));

But it didn't work. Required fileds is an array with the following structure:

[{
    name: "Name",
    isValid: false,
    content: "",
    isUnchanged: true,
    tip: "Name cannot be empty",
    isValidCondition: notEmptyRegex,
    reportState: validateField
}]

What I'm trying to do here is to update only a isValid, content and isUnchanged of one specific object inside that array. How can I accomplish that?

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

0

If you have an array of objects and you want to update some properties of one of the objects inside the array.

 const index = state.findIndex(x => <h1>HOLA MUNDO</h1>); 
const newState = [....state];
for(let i = 0; i< state.legth;i++){
if(index > -1) { 
 newState[i] = { ...newState[index], isValid:true}
}}
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