i have a javascript module name SceneModule, see the code snippet below
var SceneModule = function() {
var scene, createScene, updateScene, getScene;
scene = {
name : '',
width : 100,
height : 100
};
createScene = function(params) {
for(var key in params) {
scene[key] = params[key];
}
return this;
};
updateScene = function(params) {
scene[params.attr] = params.value;
};
getScene = function() {
return scene;
}
return {
create : function(params) {
createScene(params);
},
update : function(params) {
updateScene(params);
},
get : function() {
getScene();
}
};
};
var SceneArray = [], tempArray;
SceneArray.push(
SceneModule.create({
name : 'scene 1',
width : 100,
height : 100
}),
SceneModule.create({
name : 'scene 2',
width : 100,
height : 100
}),
SceneModule.create({
name : 'scene 3',
width : 100,
height : 100
})
);
localStorage.setItem('scene',JSON.stringify(SceneArray);
tempArray = JSON.parse(localStorage.getItem('scene'));
/**
* Print string [object object, object object, object object];
* not the SceneArray Structure;
*/
console.log(tempArray);
When I put the array of object to local storage and retrieve it, I get a string ([object object, object object, object object]) not the object array itself. I am also new to the modular architecture and local storage. I tried what many levels that i know to store and get the array of object. please review the code block. thanks in advance