0

I am trying to push data in my local storage value, but it is giving me error this.dataObj.push is not a function

Unable to find where i am going wrong, sectionObj, dataObj both are arrays, please advise

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));
}
Rakesh Chand
  • 3,105
  • 1
  • 20
  • 41
user2828442
  • 2,415
  • 7
  • 57
  • 105

0 Answers0