Ionic storage is returning expected array as a string

66 Views Asked by At

I'm storing ID's in the storage.

See example: enter image description here

I store the storage to a local string [];

The problem is when I try to push new ids to storage.

  addIdToDontShowList(id: string): Promise<any> {
    return this.storage.get(DONT_SHOW).then((ids: string[]) => {
      if (ids) {
        console.log('ids', ids);
        ids.push(id);
        return this.storage.set(DONT_SHOW, ids);
      } else {
        return this.storage.set(DONT_SHOW, id);
      }
    });
  }

I get an error that the method push does not exist on IDs.

ERROR Error: Uncaught (in promise): TypeError: ids.push is not a function TypeError: ids.push is not a function

How do I convert ids to a string [] so that I can push new items to ids before setting the storage again?

1

There are 1 best solutions below

0
D.Hodges On

I fixed this by making my initial commit to storage and array.

Instead of return this.storage.set(DONT_SHOW, id); I stored the id into and array and set it using the array.