Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda