localStorage setExpire code to add time expires
I think this code could use a lot of polishing.

Getting the localStorage

 storage =localStorage.getItem('limitStorage');
 getItems = storage !== null &amp;&amp; storage !== "[]" ? localStorage.getItem('limitStorage') : null;
 getItems = getItems !== null ? JSON.parse(getItems) : null;


can easily be replaced with:

items = JSON.parse( localStorage.getItem('limitStorage') || "[]" );


I renamed getItems to items ( getItems is a name better suited for a function ), the code also defaults items to an empty array if nothing was found.

Setting an expiry date

The easiest way to deal with that is to get now in milliseconds, add 1000 * 60 * 60 * 24 * days to it, and set that as the expiry date. Then you only have to compare (new Date()).getTime() with the expiry date.

So you have something like

var now = (new Date()).getTime();
var day = 1000 * 60 * 60 * 24;

for (var key in arrObj) {
  newItems.push( { value : key , expires : now + day * arrObj[key] } );


Now, we are facing 2 problems:


If you want to change the expiry date of an item, you cant..
Much worse, once you set some items to expire, you can never add extra items to expire since you will always fall into the else branch.


At this point, I think the whole code needs a re-write and re-think.