Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print an array in comma separated string in angular html

I have to display a parse an array inside a json in HTML:

 <p class="personaType">{{cardData.names}}</p> 

where names is

names: Array(5) 0:"Person" 1:"Artist" 2:"Performing Artist" 3:"Production Artist" 4:"Visual Artist" 5:"Intermedia Artist" 

I want to display names as:

Person, Artist, Performing Artist, Production Artist

Right now it is displaying as (without space):

Person,Artist,Performing Artist,Production Artist

Is there any inbuilt pipe available in angular which can be used to display such data?

like image 444
Always_a_learner Avatar asked May 23 '18 11:05

Always_a_learner


1 Answers

You can use Array.prototype.join (notice the white space after the comma)

<p class="personaType">{{cardData.names.join(', ')}}</p> 

This will print all the elements in the array, separated by a comma and a white space.

like image 53
bugs Avatar answered Sep 20 '22 12:09

bugs