-1

I wish to convert an Ionic's storage object to an array to be readable in a ion view. I get this error : NgFor only supports binding to Iterables such as Arrays. How to convert an object to an array ? Do i have to forEach storage the push the data to an array ? This is the object : enter image description here Regards Frank

zgue
  • 3,635
  • 9
  • 34
  • 36
  • Possible duplicate of [Typescript Convert Object to Array - because \*ngFor does not supports iteration of object](https://stackoverflow.com/questions/41458400/typescript-convert-object-to-array-because-ngfor-does-not-supports-iteration) – Red fx Oct 24 '17 at 10:04
  • Can you show your object? – Faly Oct 24 '17 at 10:17

2 Answers2

0

You can use ES6's Object.values to get an array of values:

var obj = {
  "1": { prop: "xxx" },
  "2": { prop: "yyy" },
  "3": { prop: "zzz" }
}

var arr = Object.values(obj);

console.log(arr);
Faly
  • 12,802
  • 1
  • 18
  • 35
0

I try an approch to get an array of the storage ionic object like this:

this.storage.forEach((value: string, key: string, index: number) => {
                        //console.log(key);
                        console.log('value',value);
                        });

It returns an array of the object but with additional values ! Strange ..... Solution from here