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

136
Visualizações
I want to remove item from local storage key with the function
function remove(current) {

    let text = "Are You Sure ?";


    if (confirm(text) == true) {
        current.parentElement.parentElement.remove();
        // document.getElementById("tablebody1").deleteRow(element.parentNode.rowIndex);
        text33 = JSON.parse(localStorage.getItem("storex"))

        function rem(arr, index) {
            return arr.filter(function(ele) {
                return ele != index
            })
        }

        localStorage.setItem('text32', JSON.stringify(result));
        localStorage.getItem("text32")
    }
}

I am trying to delete the items from my localstorage I render the table data on the screen but my table data is coming into the localstorage i want to delete particular item for example:

if i have localstorage just like that

0: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
1: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
2: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
3: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
4: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
5: {namex: "ANUJ", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
6: {namex: "rohit", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}

let say I want to delete 6 items. How can i do so or if i delete it when I refresh the page it come again

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

0

You can remove localstorage item with this method:

//setting item
localStorage.setItem('image', 'myCat.png');

//removing item
localStorage.removeItem('image');

about 4 years ago · Juan Pablo Isaza Relatório

0

    function example(){

  let array = [
    {namex: "1", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}, 
    {namex: "2", lnamex: "ANUJ", emailx: "anuj123@gmail.com"},
    {namex: "3", lnamex: "ANUJ", emailx: "anuj123@gmail.com"},
    {namex: "4", lnamex: "ANUJ", emailx: "anuj123@gmail.com"},
    {namex: "5", lnamex: "ANUJ", emailx: "anuj123@gmail.com"},
    {namex: "6", lnamex: "ANUJ", emailx: "anuj123@gmail.com"}
  ];
  
        localStorage.setItem('text32', JSON.stringify(array));
        
        let getDataFromLocalStorage = JSON.parse(localStorage.getItem("text32")); //convert your saved string array to object
        
        let result = getDataFromLocalStorage.filter((x, idx) => idx != 1);

        document.getElementById('ex').innerHTML = JSON.stringify(result)
}

You have to save your array as a string in local Storage so you have to get it back and convert it to Object and use filter() method. it will give all the data except 1th index object according to above example

if you want to remove 6th one you have to send the index number as 5 because array objects are start form 0th index

then save it back to local storage as a string if you want

here is the JsFiddle

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