# Storage get value

**URL:** <https://forum.ionicframework.com/t/storage-get-value/98160>\
**Category:** ionic-v3\
**Created:** [July 14, 2017, 7:27am UTC](https://forum.ionicframework.com/t/storage-get-value/98160 "2017-07-14T07:27:30Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cankaya](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@Cankaya](https://forum.ionicframework.com/u/Cankaya)\
**Post date:** [July 14, 2017, 7:27am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/1 "2017-07-14T07:27:30Z")

</div>

Hi,  
it’s OK.

```auto
		this.storage.get('buttonBool').then((data)=>{this.flag=data;});
		this.storage.get('buttonBool').then((data)=>{console.log(this.flag);});

```

But

```auto
		this.storage.get('buttonBool').then((data)=>{this.flag=data;});
		console.log(this.flag);

```

why undefined value?  
How do I use it?

---

<div class="post-metadata">

**Author:** ![auspicious](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@auspicious](https://forum.ionicframework.com/u/auspicious)\
**Post date:** [July 14, 2017, 7:53am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/2 "2017-07-14T07:53:10Z")

</div>

> [@How to get the LocalStorage value out of promise scope](https://forum.ionicframework.com/t/how-to-get-the-localstorage-value-out-of-promise-scope/57296/8):
>
> @rapropos but in case I have to do lengthy operation… then this should not be the good practice… right?? And suppose if I am retrieving two or more values from localstorage and using those two or more values for data manipulation inside single function i.e. getData()… then how it could be possible to work with them… If i have start\_time and stop\_time inside localstorage… i want to use it in the getData() function then how I can retrieve both those localstorage value…to do operation like this… …

---

<div class="post-metadata">

**Author:** ![Cankaya](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@Cankaya](https://forum.ionicframework.com/u/Cankaya)\
**Post date:** [July 14, 2017, 8:11am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/3 "2017-07-14T08:11:48Z")

</div>

```auto
	storageGet(){
		Promise.all([
		this.storage.get('name').then((data)=>{this.var=data;}),})]);
		console.log(this.var.toString());
	}

```

ı’m using above  
but same thing

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [July 14, 2017, 8:37am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/4 "2017-07-14T08:37:02Z")

</div>

Same problem: The Promises only resolve after console.log already executed. You have to use `.then` for `Promise.all` so the console.log only gets executed after all the inner Promises resolved.

---

<div class="post-metadata">

**Author:** ![Cankaya](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@Cankaya](https://forum.ionicframework.com/u/Cankaya)\
**Post date:** [July 14, 2017, 8:58am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/5 "2017-07-14T08:58:12Z")

</div>

Ok.but I use different function this.attribute undefined

```auto
	ionViewDidLoad(){
		this.storageGet();;}

```

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [July 14, 2017, 9:14am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/6 "2017-07-14T09:14:05Z")

</div>

Same problem: You execute stuff in `this.storageGet` async, then execute console.log directly while it is not yet finished. You have to return the promise in `storageGet` you get from `Promise.all` and use `then()` on `storageGet`.

---

<div class="post-metadata">

**Author:** ![Cankaya](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@Cankaya](https://forum.ionicframework.com/u/Cankaya)\
**Post date:** [July 17, 2017, 6:54am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/7 "2017-07-17T06:54:21Z")

</div>

> [@Sujan12](#):
>
> x

such is?

```auto
ionViewWillEnter(){
    Promise.all([]).then(()=>this.storageGet());
 
}

  storageGet(){
    this.storage.get('name').then((data)=>{this.var=data;});
}

```

---

<div class="post-metadata">

**Author:** ![mobgg](https://avatars.discourse-cdn.com/v4/letter/m/ea666f/32.png) [@mobgg](https://forum.ionicframework.com/u/mobgg)\
**Post date:** [July 17, 2017, 7:11am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/8 "2017-07-17T07:11:06Z")

</div>

i think it should be

```auto
var promise1= this.local.get('id');
var promise2 = this.local.get('name');

Promise.all([promise1, promise2]).then((arrayOfResults) => {
console.log(arrayOfResults[0]);
console.log(arrayOfResults[1]);
});

```

---

<div class="post-metadata">

**Author:** ![Cankaya](https://avatars.discourse-cdn.com/v4/letter/c/74df32/32.png) [@Cankaya](https://forum.ionicframework.com/u/Cankaya)\
**Post date:** [July 17, 2017, 7:26am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/9 "2017-07-17T07:26:00Z")

</div>

storageGet function console write  
but ionViewWillEnter console not write

```auto
  ionViewWillEnter(){
    this.storageGet();;}

storageGet(){
    var x0=this.storage.get('name');

  Promise.all([x0]).then((arrayOfResults) => {
    this.var=arrayOfResults[0]; console.log(arrayOfResults[0]);
  });

```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [July 17, 2017, 8:15pm UTC](https://forum.ionicframework.com/t/storage-get-value/98160/10 "2017-07-17T20:15:49Z")

</div>

As I said in the thread that @auspicious linked to earlier, I think your code would be more performant as well as far easier to read, write, and maintain, if you would just combine all of these properties into a single JSON interface instead of storing them all separately.

---

<div class="post-metadata">

**Author:** ![lydia-sebastian](https://avatars.discourse-cdn.com/v4/letter/l/6bbea6/32.png) [@lydia-sebastian](https://forum.ionicframework.com/u/lydia-sebastian)\
**Post date:** [July 18, 2019, 9:33am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/11 "2019-07-18T09:33:13Z")

</div>

I am facing exact same issue do you has a solution to this problem

---

<div class="post-metadata">

**Author:** ![sandeepjohnsonk](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sandeepjohnsonk/32/127371_2.png) [@sandeepjohnsonk](https://forum.ionicframework.com/u/sandeepjohnsonk)\
**Post date:** [July 30, 2019, 7:33am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/12 "2019-07-30T07:33:17Z")

</div>

you use method async and get storage value await storage.get

---

<div class="post-metadata">

**Author:** ![webrexRavi](https://avatars.discourse-cdn.com/v4/letter/w/ecd19e/32.png) [@webrexRavi](https://forum.ionicframework.com/u/webrexRavi)\
**Post date:** [August 5, 2019, 9:36am UTC](https://forum.ionicframework.com/t/storage-get-value/98160/13 "2019-08-05T09:36:47Z")

</div>

**Found Perfect Solution** on [stackoverflow](https://stackoverflow.com/questions/48926248/get-ionic-storage-item-as-a-string#)

> <https://stackoverflow.com/questions/48926248/get-ionic-storage-item-as-a-string>
