title: Javascript localStorage not working it overwrites object
body: <p>I have 20 buttons and 20 links and descriptions inside info_array.
  I add click event listener to each button.
  On click function inside addEventListener must save unique info inside <strong>localStorage</strong> with incrementing object keys on each new button click.</p>
  <p>Problem is that function works and saves Objects with unique value inside localStorage like 0,1,2,3,... till <strong>10th</strong> object. When object keys reach 10 then 11th object with key 11 is not saving  in localStorage, code just overwrites 10th object every time i clicked 11th,12th,13th,... button just overwrites value of 10th object rather creating and saving new object with new object key like 11,12,13,14,...</p>
  <p>I can't understand what is wrong with my code because it works till 10th object.</p>
  <p><strong>Code:</strong></p>
  <pre><code>for (let i = 0; i &lt; 19; ++i) {
  
      let btn = document.createElement('BUTTON');
  
      btn.addEventListener('click',function(e){
          e.stopPropagation();
  
          let newsList = localStorage,
          keys         = Object.keys(localStorage).sort(),
          match        = false,
          news         = {
              &quot;title&quot;:info_array[i].title,
              &quot;description&quot;:info_array[i].description
          };
  
          if (nl.length &gt; 0) {
  
              // check if element exists in localStorage
              for(let n = 0; n &lt; newsList.length; ++n){
                  if (JSON.parse(newsList[keys[n]]).link == info_array[i].link) {
                      match = true;
                  }
              }
  
              // if object is unique save in localStorage
              if (!match) {
                  let key = (parseInt(keys.pop())+1).toString();
                  localStorage.setItem(key,JSON.stringify(news));
              }
              
          }else{
              // if localStorage is empty add first object
              localStorage.setItem(0,JSON.stringify(news));
          }
  
      },{passive:true});
  
      html.appendChild(element);
  }
  </code></pre>