I am learning JS these days and making a chrome extension. I want to store user data in chrome's storage API. And I want to ensure if the user has downloaded the extension for the first time then the variable should be 0 else change dynamically.
"use strict";
// chrome.storage.sync.clear()
chrome.storage.sync.get("totalviews",function(views){
if (views.totalviews){
console.log("There")
}
else{
console.log("Not there")
chrome.storage.sync.set({"totalviews":0})
console.log("Done!!")
}
})
However I am not able to update the variable to 0 if it does not exists. Any help?