0
var arr=[
        {Key0: "myValue1"},
        {Key0: "myValue2"},
        {Key0: "myValue3"},
        {Key1: "myValue4"},
        {Key2: "myValue5"}, ]

from the above array, I want to get the values using its key in *ngFor angular, for example, key0 values I want to display along with other values values,

I have also tried like this but can't able to get the desired output

                         <li mat-list-item *ngFor='let C of arr'>
                             {{C}}</li>

Note:

I tried like {{c.key0}} but it prints only key0 values, but here I want all the values like key1,key2

thanks in advance.

Community
  • 1
  • 1
siva IT
  • 51
  • 9
  • How many keys are you expecting? – MonkeyScript Feb 06 '19 at 08:58
  • Possible duplicate of [access key and value of object using \*ngFor](https://stackoverflow.com/questions/35534959/access-key-and-value-of-object-using-ngfor) – ForestG Feb 06 '19 at 08:58
  • Possible duplicate of [How to iterate object keys using \*ngFor](https://stackoverflow.com/questions/41396435/how-to-iterate-object-keys-using-ngfor) – Swoox Feb 06 '19 at 08:59
  • I want to get almost all the values in array using its key @Arcteezy – siva IT Feb 06 '19 at 09:00

2 Answers2

1

As shown in: How to iterate object keys using *ngFor

You can use (angular v6+):

<div *ngFor='let C of arr | keyvalue">
   {{C.key}}:{{C.value}}
</div>
Swoox
  • 3,707
  • 2
  • 21
  • 32
1

I think you should modify your array in typescript first by using iteration logic. And then show it using *ngFor.

Sufyan Shaikh
  • 94
  • 1
  • 6