sotre json on chrome storage

Solutions on MaxInterview for sotre json on chrome storage by the best coders in the world

showing results for - "sotre json on chrome storage"
Irene
09 Apr 2017
1var local = (function(){
2
3    var setData = function(key,obj){
4        var values = JSON.stringify(obj);
5        localStorage.setItem(key,values);
6    }
7
8    var getData = function(key){
9        if(localStorage.getItem(key) != null){
10        return JSON.parse(localStorage.getItem(key));
11        }else{
12            return false;
13        }
14    }
15
16    var updateDate = function(key,newData){
17        if(localStorage.getItem(key) != null){
18            var oldData = JSON.parse(localStorage.getItem(key));
19            for(keyObj in newData){
20                oldData[keyObj] = newData[keyObj];
21            }
22            var values = JSON.stringify(oldData);
23            localStorage.setItem(key,values);
24        }else{
25            return false;
26        }
27    }
28
29    return {set:setData,get:getData,update:updateDate}
30})();
31