I am fetching data from apex class in a local map variable in LWC javascript.Even after using @track my output is getting duplicated.As in, opn calling the methods the old data is not replaced with new ones's.Another set of new data is getting added under the old data.
import getGroups from '@salesforce/apex/LC_onBoardingController.getGroups';
@track mapOfGroups = [];
handleLoadGroups() {
getGroups()
.then(result => {
if (result) {
for (let key in result) {
if (result.hasOwnProperty(key)) {
this.mapOfGroups.push({ value: result[key], key: key });
console.log("groupsmap***"+JSON.stringify(this.mapOfGroups));
}
}
}
})
.catch(error => {
window.console.log("groupsmap***error");
});
}
On click of a button i am calling a method say
backtoGroups(event) {
this.handleLoadGroups();
this.UserStage = "GROUPS";
}
So the new data is coming but its getting appended to the old one instead of getting replaced. Is there something I am missing or doing mistake in?