Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

601
Visualizações
How to remove ıtem on localStorage?

I want to removeItem on localstorage but ı dont use localstorage.removeItem().Because ı want to delete a index in array(Sepet=array) How can ı do it ? thx

Sepet Array

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

var array = [
{
'id': 1,
'name':'test1'
},
{
'id': 2,
'name':'test2'
},
{
'id': 3,
'name':'test3'
}
];

console.log(array);
localStorage.setItem('test', JSON.stringify(array));
var selected = 1;
 var getArray = JSON.parse(localStorage.getItem('test'))
getArray.splice(selected,1);
localStorage.setItem('test', JSON.stringify(getArray));
console.log(getArray);

about 4 years ago · Juan Pablo Isaza Relatório

0

localStorage is meant to store String values, so if you want to remove an item at a particular index, bear in mind that you need to convert the stringyfied array into plain JS array, then remove the item with array.slice(), and save the updated array back to localStorage.

You can checkh the Array.slice() documentation

about 4 years ago · Juan Pablo Isaza Relatório

0

To get object from localStorage you need the Helper: localStorage.getItem('objectName');. You will get a string and not a object. To transform this string to a Object you need the function JSON.parse(string). And on this point you can work with the object. If you will delete item by index then remove it with object[index]and if you will remove item by value key like id: 2 then use JS Object function function like spliceto remove this item.

After that you have to stringify the object again to a string with JSON.stringify(object). This string you can store in the lcoalStorage withe the methode: localStorage.set(string)

That is the entire workflow.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda