I want to set a key value but I only want to do it if it does not exists already.
In my component1.ts
file, I am setting the key and the value in the constructor but I want to add a check that this command should only execute if the key is not created before. If the key is already present there, don't execute.
Below is my code:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
myname='';
list: Array<string> = ['a','b','c'];
sectionObj = {};
getresume = {};
stored_name = '';
constructor(public navCtrl: NavController) {
this.sectionObj = { "name" : this.myname,
"contactno" : "0",
"email" : "a@a.com"
};
// below line should only execute if "resume" key does not exist
localStorage.setItem("resume",JSON.stringify(this.sectionObj));
}
}
Please advise