How to get property value


#1

i have a Promise which i used to get the stored data of in an Ionic storage

return new Promise(resolve => resolve(this._storage
.get(“user”)
.then(value => value)));

and it prints out {“user-profile”:“user”,“acct_no”:“1234567890”}

how do u get the value of acct_no?


#2

The question sounds backwards, because it looks to me like value has a property acct_no, not the other way around.


#3

i have corrected it, how do i get the value of acct_no? which will be in this case 1234567890


#4

I really hate property names like “value” and “data” that convey no meaningful information, but {{value.acct_no}}.


#5

just correct your code to this

return new Promise(resolve => resolve(this._storage
.get(“user”)
.then(value => value.acct_no)));


#6

There is absolutely no need to instantiate a new Promise here. Storage gives you a perfectly good one.