How remove a single data which is store in a single key in ionic storage


#1

I am trying to make a note app by ionic where i am using storage plugin. i set a key

  private note: note[] = [
     title: string;
    note: string;
];
  constructor(private storage: Storage) {

  }

  addNote(note: note) {
    this.note.push(note);
    this.storage.set('note', this.note);
  }


getNote() {
    return this.storage.get('note')
    .then(
        (note) => {
            this.note= note== null ? [] : note;
            return this.note.slice();
        }
    )
  }

where all data are array object, like

(3) [Object, Object, Object]
0:Object
1:Object
2:Object
length:3

I just want to remove a single array object inside this note array. I tried this.storage.remove(note[index]); but its dont work.


#2

Please make your classes start with capital letters, so you don’t end up with such confusing conflicting-looking things like note: note[].

If this is a common operation, maybe you might want to restructure the data so that each Note gets its own UUID as a key; that way deleting one is easy.

The way you have it now, you’re going to have to read the entire array in, take an element out, and then write the modified array back to storage.