How to replace existing key values with new one in ionic local storage'current').then(token => {
 this.presentAlert('Existing Current data',JSON.stringify(token));'current',;

I wanna replace the existing current values with new data. But storage.set is not replacing it.
Should i use storage.remove() ? to first remove the existing values and then add new by setting it again?
What is the best way?
Thank you.

Yes! The local storage accept add value if exist array, but not change the value…

Your need delete the value and create again!


I don’t think I agree with the previous post.

alpha = "";
beta = "";
gamma = "";

constructor(private storage: Storage) {}

ngOnInit(): void {
  .then(() =>"key", "apple"))
  .then(() =>"key").then(a => this.alpha = a))
  .then(() =>"key", "banana"))
  .then(() =>"key").then(b => this.beta = b))
  .then(() =>"key", "cherry"))
  .then(() =>"key").then(c => this.gamma = c));
  <ion-item><ion-label [innerText]="alpha"></ion-label></ion-item>
  <ion-item><ion-label [innerText]="beta"></ion-label></ion-item>
  <ion-item><ion-label [innerText]="gamma"></ion-label></ion-item>

I see “apple”, “banana”, and “cherry” as I would expect.

1 Like