I have this original array objects:
const students=[
{ "name": "sean"},{"name":"paula"}
];
I am trying to update the object where student.name==="sean"
to "jason"
I want to avoid update the original array object
console.log(students); // should be {"name": "jason"},{"name": "paula"}
console.log(findStudent); //output is {"name":"jason"} (desired result)
const students=[
{ "name": "sean"},{"name":"paula"}
];
const findStudent= students.find((student)=>student.name==="sean");
findStudent.name="jason";
console.log(findStudent); //output is {"name":"jason"} (desired result)
console.log(students); // output is {"name": "jason"},{"name": "paula"} (wrong result)
, how to avoid it?