const arr=[]
let id=0
app.post('/book',(req,res)=>{
payload={body: req.body,id: id+1}
id=id+1
arr.push(payload)
console.log("arr",arr);
return res.send("success")
})
`this is how I created the push function in an array with default id
i try to delete element from this array by its id using pop or using some loop`
2
Answers
first of all you need to convert the id into number then use filter to delete the required element like so:
This is a tested snippet which works successfully:
I’m:
Tested with an id of 3, you can use the value you want instead.