Reputation: 53
I am trying to save a variables data to local storage, but after .get() call console-output is "1 result[object Object]" and in "2 result[object Object]".
function save_data(key_name, data){
console.log(key_name + ' '+ data);
var obj = {};
obj[key_name] = data;
chrome.storage.local.set(obj);
}
function load_data(key_name){
chrome.storage.local.get('key_name', function(result){
console.log('1 result' + result);
//console-output:"1 result[object Object]"
});
chrome.storage.local.get(key_name, function(result){
console.log('2 result' + result);
//console-output:"2 result[object Object]"
});
}
Upvotes: 0
Views: 59
Reputation: 8201
This is an issue with type casting. You are trying to add an object to a string, which is the same as using the toString()
method on an object which will always output "[object Object]"
.
Instead of adding them, use a comma like so:
console.log('1 result',result);
There is a pretty good resource for info about types in javascript here.
Upvotes: 2