Last Updated: February 25, 2016
·
588
· piatra

Trick with localStorage

I've been using this trick more an more lately to store data permanently in the browser.

data = JSON.parse(localStorage.getItem('data')) || [];
data.push({
  name: 'Andrei',
  age: 20
});
localStorage.setItem('data', JSON.stringify(data));

I've found it to be very useful. It's localStorage so it's on mobile too!
Support (http://caniuse.com/#feat=namevalue-storage)
* android 2.1
* IE 8+
* everyone else