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

108
Vistas
how to update the array object using id and the props in javascript

I have an array object and I want to update the array object using id and props.

below is the structure of array object,

array object = [{columGrp:"All",deafultColumnName:"a",id:0},{columGrp:"ll",deafultColumnName:"ww",id:1},{columGrp:"oo",deafultColumnName:"qq",id:2},{columGrp:"qq",deafultColumnName:"ee",id:3}]

I have an editable table design and when a field changes I am passing field name, id, and changed value. based on that how can I update the object array.

const onChange=(props,value,id)=>{
   //code here
}
onChange("columGrp","qwerty",1);
 // result =>
 array object = [{columGrp:"All",deafultColumnName:"a",id:0},{columGrp:"qwerty",deafultColumnName:"ww",id:1},{columGrp:"oo",deafultColumnName:"qq",id:2},{columGrp:"qq",deafultColumnName:"ee",id:3}]

a help would be really appreciable.

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

0

You can find the object by id from your array of objects using the filter function. If the object exists, you then change the given property, passing the given value. Objects work by reference in javascript so any changes in the found object will affect your object inside your array too.

const objectsArray = [{
  columGrp: "All",
  deafultColumnName: "a",
  id: 0
}, {
  columGrp: "ll",
  deafultColumnName: "ww",
  id: 1
}, {
  columGrp: "oo",
  deafultColumnName: "qq",
  id: 2
}, {
  columGrp: "qq",
  deafultColumnName: "ee",
  id: 3
}];

const onChange = (props, value, id) => {
  const obj = objectsArray.find(x => x.id === id);
  if (obj) {
    obj[props] = value;
  }
}

onChange("columGrp", "qwerty", 1);

console.log(objectsArray)

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