Dhaval Patel
Dhaval Patel

Reputation: 83

angular 9 show array of object'values one by one

[
{"_id":"5e56579e97dd2029e407f89d","name":"Loka","mobileno":25689,
 "type":"D","gender":"Male","__v":0},
{"_id":"5e578a70547cff4058b26ee1","name":"NNN","mobileno":36954,
 "type":"D","gender":"Male","__v":0},
{"_id":"5e57c02ece0c6928ac575798","name":"ssss","mobileno":855,
 "type":"B","gender":"Male","__v":0},
{"_id":"5e57c33ece0c6928ac57579a","name":"ssss","mobileno":859,
 "type":"B","gender":"Male","__v":0},
{"_id":"5e57c360ce0c6928ac57579b","name":"ssss","mobileno":5486,
 "type":"B","gender":"Female","__v":0},
{"_id":"5e57c407ce0c6928ac57579c","name":"Dhaval","mobileno":24569,
 "type":"C","gender":"Female","__v":0}
]

I want to fetch each value from above Array of objects. I wrote below code for above array

<div *ngFor="let items of customers">
  {{items}}
</div>

I want Output like

Name:Dhaval type: C

Upvotes: 2

Views: 190

Answers (4)

prasad07
prasad07

Reputation: 211

I have created an example for showing value. Refer below link for the same.

angular 9 show array of object'values one by one

Hope this help.

Upvotes: 1

Pramod Kharade
Pramod Kharade

Reputation: 2085

<div *ngFor="let items of customers">
    {{items.name}} {{items.mobileno}} {{items.type}} {{item.gender}}
</div>

You can traverse array of object with respective keys.

Upvotes: 3

Swoox
Swoox

Reputation: 3740

Think what you're looking for is the keyvalue pipe.

<div *ngFor="let items of customers">
  <div *ngFor="let item of items | keyvalue">
     {{item.key}}: {{item.value}}
  </div>
</div>

Source: https://angular.io/api/common/KeyValuePipe

Upvotes: 1

Kurt Hamilton
Kurt Hamilton

Reputation: 13515

If you want to output a message for each item in the array, you can just use interpolation.

<div *ngFor="let items of customers">
  Name:{{items.name}} Type:{{items.type}}
</div>

Upvotes: 1

Related Questions