What I am trying to do is update a single value in an array this is the code I have so far for it but it doesn't seem to be working correctly, was wondering if anyone would be able to help me with this.
So, how I think it works is it takes the index position from the ngFor as well as the auto-incrementing id for the array makes sure it has a match and pushes the new name to the array.
But that doesn't seem to be working, it executes the toastr to say it has been updated but it hasn't in the Local Storage
public updateNameLocalStorage(Name, id, i ): void {
const currentArray = this.storage.get(this.STORAGE_KEY);
console.log(currentArray);
for (i = 0; i < currentArray.length; ++i) {
if (currentArray[i].id === id) {
currentArray.push({
Name: Name
});
// insert updated array to local storage
this.storage.set(this.STORAGE_KEY, currentArray);
this.notifiy.showInfo('Name Updated' , '');
} else {
this.notifiy.showFailure('Error' , '');
}
}
This is the structure of the data