title: Javascript Localstorage: Comparing input value with value stored in array in localstorage
body: <p>My purpose is to check if value entered by user in the input field is already available in an array stored in the localstorage. If yes, print the array if not add the new value in the storage. I am getting my array back on button click but the code isn't working correctly. The output is:
  ["hh", "try", "vogue", "vogue", "try2", "try2", "try2", "try2"] </p>
  
  <p>Above are the entered values which are getting added repetitively. I know it's a stupid issue but have least experience with handling arrays in localstorage. Any help would be appreciated. (I tried the solutions provided in similar questions on stackoverflow but no luck) </p>
  
  <pre><code>&lt;html class=" reevoomark_ATY"&gt;
      &lt;head&gt;&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
          &lt;title&gt;Special Offers&lt;/title&gt;
          &lt;script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ="crossorigin="anonymous"&gt;&lt;/script&gt;
      &lt;/head&gt;
  &lt;body&gt;
      &lt;input id="coupon"&gt; &lt;button style="width:50px;padding:10px;background:grey;height:30px;border:1px solid grey" id="button"&gt;Apply&lt;/button&gt;
      &lt;input id="stored"&gt;
      &lt;script&gt;
  
              var coupons = ['hh'];
              var storedNames;
              localStorage.setItem("coupons", JSON.stringify(coupons));
              $('#button').on('click', function(){
                  storedNames = JSON.parse(localStorage.getItem("coupons"));
                  var enteredValue = $('#coupon').val();
                  for(i=0; i &lt;storedNames.length; i++) {
                      if(enteredValue === storedNames[i]) {
                          console.log("value Exist!!");
                          console.log(storedNames[]);
                      }
                      else {
                         console.log("in else");
                          coupons.push(enteredValue);
                          localStorage.setItem("coupons", JSON.stringify(coupons));
                          storedNames = JSON.parse(localStorage.getItem("coupons"));
  
                      }
  
                      }
  
  
  
              });
  
  
  
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>