I am working on a Budget App and trying to make the edit and delete buttons work. I am using an onClick to trigger the functions and passing the parameters of the object aka “id”, and “object” as seen in the first screenshot. Am I making a mistake in the syntax or logic? Because, upon console logging, the “id” is passed successfully but not the “object” (As seen in the second screenshot).
Also what logic can be used in order to delete the particular entry from localStorage? It’s been a while since I have worked on JS, so need the help.
Syntax of the object getting saved in localStorage :
{id: 1, object: “pen”, price: “20”}
both the rewriteItem( ) and deleteItem() are being called using onClick as shown in the first screenshot. In rewriteItem (), I have tried to pass the required arguments while in the deleteItem() , I was trying to pass the event to execute the function (just to try which method was working better). Unfortunately, in both methods I ended up encountering issues:
Object being undefined when I try to use the argument passing option.
Not able to figure out how to delete the item from local Storage when using the event passing option.
<button><i class="fa-solid fa-pen-to-square edit" onClick="rewriteItem(${id,object})"></i></button>
Here: ${id,object}
You need to add a , manually between id and object, or else it will only insert one of them (I think the last one) document.write(${123, “abc”}) results in abc document.write(${123 +", "+“abc”}) results in 123,abc
But you said it’s only getting the id, so there is an error already earlier