Well, foremost your
editItem
method doesn't seem to take in any parameters which contradicts the
onclick
attribute in the HTML. Did you mean for the method to look like this:
function editItem(event, index) {
That's better, now you have the index of the item that you want to edit. Remember that
window.localStorage.getItem()
returns a
string
value, it doesn't automagically do anything else. You need to take the content and parse it back into an array:
const json = window.localStorage.getItem(USERINPUT_KEY);
const array = JSON.parse(json);
Now you have the array and the index, you can access the individual item using the index, and do something with the result. Bear in mind you haven't provided us with the HTML for the form used to add/edit entries, so that part is down to you.