我正在尝试将数据推送到我的本地存储值,但是它给了我错误this.dataObj.push
不是函数
无法找到我出错的地方,sectionObj,dataObj都是数组,请指教
file.ts
myname = '';
sectionObj = [];
getresume = {};
dataObj = [];
data = '';
save() {
this.sectionObj = [{
"name": this.myname,
"contactno": "0",
"email": "a@a.com"
}];
this.data = localStorage.getItem('resume'); //get existing item in localstorage
if (this.data) //check if it exists or not empty
{
this.dataObj = JSON.parse(this.data); //parse string
this.dataObj.push({
"name": this.myname,
"contactno": '2',
"email": "a@a.com"
});
}
localStorage.setItem("resume", JSON.stringify(this.dataObj));
}