Reputation: 3402
I have dynamically generated inconsistent array of Objects from API(server).
E.g:
array = [
{name: 'blah', age:2},
{status: 'pending', date: '20-20-2020'},
{blah: 'foo', google: 'bar'},
{apple: 'android', microsoft: 'eeewww'}
]
this array could be anything with different keys and values.
how can i Iterate through it to show the values in
ngFor
?
What I am currently is doing:
this.printArray = JSON.stringify(JSON.parse(this.array), null, 4);
<div *ngFor="let print of printArray">
{{print}} // it prints the array like {"name": blah, "age": 2} but i don't want it in this way
</div>
Upvotes: 0
Views: 188
Reputation: 58029
You can use Angular keyvalue pipe
<div *ngFor="let element of myArray">
<!--element is an object-->
<div *ngFor="let item of element|keyvalue">
{{item.key}}:{{item.value}}
</div>
</div>
Upvotes: 6