6

I need to clear amplifyjs storage, remove all key-values. Smth similar to localStorage.clear().

Thanks in advance.

Ulad Melekh
  • 924
  • 3
  • 17
  • 33

1 Answers1

8

The docs for amplifyjs indicate that you can clear (remove) a specific storage key by storing the value null to that key:

amplify.store( "MyKeyName", null );

We can get all of the current storage key names with: amplify.store() and then use jQuery $.each to go through the list and clear (remove) each of the items currently stored in 'amplifyjs storage':

$.each(amplify.store(), function (storeKey) {
    // Delete the current key from Amplify storage
    amplify.store(storeKey, null);
});

You could put this code into a function and call it or use it inline somewhere, but I'd probably add the function to amplifyjs at runtime with something like:

amplify.clearStore = function() {
    $.each(amplify.store(), function (storeKey) {
        // Delete the current key from Amplify storage
        amplify.store(storeKey, null);
    });
};

and then call that with amplify.clearStore();

zengr
  • 38,346
  • 37
  • 130
  • 192
David Tansey
  • 5,813
  • 4
  • 35
  • 51