I tried to update normal array data its sucessfully updated.but I have a doubt.I pass id in put url and get id to compare the array.its id is there its get data and stored another variable then that variable used to chanage the value.and its automatically change value in original array.How its possible any one can explain
app.js
const courses = [{id:1,product_name:"bourbon"},{id:2,product_name:"bourbon"}]
router.put('/:id',(req,res) =>
{
console.log("hello")
console.log(req.params.id)
for(let i=0;i<courses.length;i++)
{
if(courses[i].id === parseInt(req.params.id))
{
let course = courses[i]
course.name = "hari"
console.log(courses)
}
}
})
My put url
localhost:3000/woc/1
I got Output
[{id:1,product_name:"bourbon"},{id:2,product_name:"hari"}]