LS not stopping dupes

LS not stopping dupes

  1. (function() {
  2. //localStorage.clear();



  3.    //     Parse the JSON stored in allEntries
  4. var existingEntries = JSON.parse(localStorage.getItem("allEntries"));
  5.       if(existingEntries == null) existingEntries = [];
  6.       var entry = $(".entry").text();
  7.       
  8.              localStorage.setItem("entry", JSON.stringify(entry));

  9.                // Save allEntries back to local storage
  10.                existingEntries.push(entry);

  11.                localStorage.setItem("allEntries", JSON.stringify(existingEntries));
  12.             
  13. })();



   
  • How can I go about stopping the addition of a localStorage item if it already exists?
  • I had this snippet in the code but wasnt working.
    1. var getAll = JSON.parse(localStorage.getItem("existingEntries"));
                  for(var i = 0; i < getAll.length; i++){
                  //console.log(getAll[i]);
                    //
                  var x = getAll[i];
      if (entry == x){

      //then dont setItem




      }}

    1. https://codepen.io/shawnbks9090/pen/vjgyzo
    this is the only html:

    1. <span class="entry">hello</span>