output+=<td> <button onclick='addFavourite(${rec.id},${rec.Title},${rec.Posterpath})'>Add to Favourites</button></td>;
This is the fuction which take arguments, and add it into the favourite part in json, using fetch, and also it also display at web as a table.
function addFavourite(value,title,poster) {
let ind= itemarr.findIndex( ele=>ele.id==value);
datastore= {
"id": value,
"Title" : title,
"Posterpath": poster
}
fetch("http://localhost:3000/favourites",{
"method":"POST",
"headers":{"content-type":"application/json"},
body:JSON.stringify(datastore)
})
.then(
res=>
{
console.log("Added");
itemarr2.push(datastore);
displayproduct2();
}
)
.catch(
err=>console.log(err)
)