JSFiddle - React, Tailwind, and code Playground

set/store localstorage

by Christopher O

JavaScript

console.clear();

let now = 'test'; //+Date.now();

let omb = {};

console.log('typeof: '+typeof localStorage[now]);

if (typeof localStorage[now] != undefined) {
  console.log(now+' is defined: '+localStorage[now]);
  omb = JSON.parse(localStorage[now]); // JSON.parse returns obj
}else{
	console.log(now+' is NOT defined');
}
omb.id = 'id_'+now;

console.log('omb: '+JSON.stringify(omb));
localStorage[now] = JSON.stringify(omb);

/* localStorage[now] = '{"a":123,"b":458}'; */