I have an array of objects. But sometimes this is just a pure object and in such cases my loop fails. How do I prevent this.
for(let singleItem of myObj){ // this works fine when I get an array of objects
myArray.push({
'Item 1': singleItem .Prop1.text,
'Item 2': singleItem .Prop2.text
})
}
I get an error on for.....of when I have no array but just an Object with key values.
When I get the error, my object `myObj` will be like this.
{
Prop1: { text: 'testvalue' },
Prop2: { text: 'testvalue1' }
}
How do I ensure that I can fill my array myArray without any error?