Good Afternoon all, I am currently learning JavaScript, My task is to remove items from localStorage. The set keys are timestamps for example // Make a key using a fixed timestamp key = "diary" + "1536771000001";. // Make a key using a fixed timestamp key = "diary" + "1536771000002"; (ETC) Code (JavaScript): However, when i go to remove these items using localStorage.removeItem('diary1536771000002'); every time i click the delete button on any item it removes the diary1536771000002 all the time and not the right key for that text item. I am not looking for the direct answer but can someone point me in the right direction?
I suspect that you have the delete buttons calling the same function but the function has the key hardcoded. An alternative might be to have buttons with data-key='diary1536771000002' and then the click event picks up the dataset.key value.