Get multiple values at same time using Ionic Storage


I used Ionic Storage.
I saved this data:'key1', 'value1');'key2', 'value2');

How I can get all data at same time, example: for compare:

if (key1 == key2) {
  // do something


1 Like

The best way would probably be the store both values as a single object, i.e:

let data = {
  key1: 'value1',
  key2: 'value2'

then just load that object in.


If @joshmorony’s suggestion isn’t appropriate (if, for example, the two values are set independently), Promise.all would be another option.

1 Like

Try this out:

storage.forEach((index, key, value) => {
	console.log(index, key, value);

This will return you everything stored in your storage.

1 Like

I’m not seeing how that returns anything.

Take a look here:

   * Iterate through each key,value pair.
   * @param {any} iteratorCallback a callback of the form (value, key, iterationNumber)
   * @returns {Promise} Returns a promise that resolves when the iteration has finished.
  forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any): Promise<void> {
    return this._dbPromise.then(db => db.iterate(iteratorCallback));


storage.forEach((index, key, value) => {
	console.log(index, key, value);

should return every stored key<->value pair with the index.

Again, I don’t see it returning anything. I see it logging things to console, which is useless when one is trying to do something with the data.

1 Like

Thank You

data = {
key1: ‘value1’,
key2: ‘value2’

data2: string = ‘’;,; => {
console.log(‘data is’, val[‘key1’]);