Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!