0

I have an array of contacts in local storrage, and I need to remove, for example, the first element. How better to do? Is this expression correct?

          localStorage.removeItem("allContacts"[0]);
1

1 Answer 1

0

localStorage contains string values. If you stringifyed an array and put it into localStorage, then you'll need to parse the array, delete the element you want, and then set the localStorage property again:

const allContacts = JSON.parse(localStorage.allContacts);
allContacts.shift();
localStorage.allContacts = JSON.stringify(allContacts);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.