Ionic 2 storage - get all stored keys forEach method

Hi there!
Can please someone give me an example on how I can get all available stored keys in Ionic storage using forEach method of storage object?



Never used ionic-storage, but looking at the implementation here

* Iterate through each key,value pair.
* @param iteratorCallback a callback of the form (value, key, iterationNumber)
forEach(iteratorCallback: (value: any, key: string, iterationNumber: Number) => any) {
return this._db.iterate(iteratorCallback);

I guess this might work: (value, key, index) => {
	console.log("This is the value", value)
	console.log("from the key", key)
	console.log("Index is" index)

It works! Thanks very much. Do you know if there are any limitations regarding the size that can be stored using Ionic storage? The docs are saying that “Storage will prioritize using SQLite”, so I wonder if the same limits as SQLite are applied for the Ionic storage too.


1 Like

I’m glad I could help :slight_smile:
About your latest question, I’m really not sure.

Thanks, works for me too!

Yes, this works and it can iterate items from storage!
But how can I fetch items on html using *ngFor?

I see items displaying in console.log but I have no idea on how to put them in an array which I can use with *ngFor let of directive…

in your .ts file:

extractData () { ('name of your key'). then ((val) => {

      this.Content = val;

      this.Reports = [this.Content];


in your .html file (use *ngFor )

     <ion-item *ngFor="let report of Reports;" tappable>
         <ion-avatar item-left>
           <img src="img/camarista.png"> 
        <ion-label text-wrap>
                <span col-10 class="informe">{{report.title}}  <!--
You get the value of an element contained in the array -->
                  <ion-icon name="arrow-forward"></ion-icon></span>


(the additional elements depend on your need)