I am working on a function that handles checkbox options based on event.target.name. The goal is to add the checkbox option to session storage if it's not already there, and update the value if it exists. However, I'm facing some issues with my code. Can you help me identify which part needs fixing?
saveSetting(event){
const getSesssion = sessionStorage.getItem('setting');
if(getSesssion) {
const parseSession = JSON.parse(getSesssion);
parseSession.forEach((item) => {
if(item.setName === event.target.name) {
this.changeValue = !this.changeValue;
item.setValue = this.changeValue;
parseSession.pipe(map(item => this.settingList.push({ setName: event.target.name, setValue: this.changeValue })));
sessionStorage.setItem('setting', parseSession);
}
});
} else {
this.settingList.push({ setName: event.target.name, setValue: true });
const parseList = JSON.stringify(this.settingList);
sessionStorage.setItem('setting', parseList);
}
}
I need to update the value in session storage if it already exists.