I'm assuming your deleteData is an event handler. In that case, event is of Event type. Assuming that the object this handler is attached to contains the data you want to delete in some way, you could do something like:
const deleteNote = (event) => {
const data = Array.from(JSON.parse(localStorage.getItem("notes")));
// Return the note you want to delete
const itemToDelete = data.filter(function(item) {
// ideally, I'd store the note (as a JSON string) in data attribute, so this is what I'd do. Otherwise use JSON.parse(event.target.value). JSON strings stored in data attributes should be automatically converted to a JS object when retrieved.
return item === event.target.dataset.note;
});
// filter returns an empty array if nothing meets the conditions.
if (itemToDelete.length) {
// Deletes the note from data.
data.splice(data.indexOf(itemToDelete[0]), 1);
}
// Update localStorage to new data.
localStorage.setItem("notes", JSON.stringify(data));
};
event refers to the Event that occurred (it contains properties like target, type, timeStamp, and others, but target is what we need). event.target refers to the object (DOM Element) that the event occurred on.
In order to filter the correct data, you will need to attach the note in some way that the handler is attached to. Assuming (based on provided code) that you have a delete button/anchor per note, the note should be referenced on the anchor/button in a data attribute. For example:
<a href="/crud/delete/route" data-note="{\"title\":\"one\",\"text\":\"one\",\"date\":\"2022-08-10\"}">delete</a>
(proper JSON string can only use double-quotes, hence the escapes...could enclose JSON string in single-quotes but I prefer to keep formatting consistent).
You wouldn't obviously want to type the note manually, I only did this to provide an example. I'd supply the data nodes programmatically on the JS end using DOM manipulation. If this is React or a templating language then it is even easier.
In either case, in your filter, you need to be more specific, since event will not be equal to a note as mentioned above, whether you use a data attribute or set a value to equal the item.title or something, as other answers suggest.
event? Is it atitle,text?eventis an object that looks like{title: 'one', text: 'one', date: '2022-08-10}?