Reputation: 352
I have this following pug array and let it execute in an each. The problem is the values are listed with commas. I want it without commas.
I could write the array in the each like each x, y in {'value1': 'value2', ...}
but that isnt comfortable.
The current code:
-
var starWars = {
"people": [
"Yoda",
"Obi-Wan",
"Anakin"
],
"rank": [
"master",
"master",
"knight"
]
}
each person, rank in {starWars}
p= person.people
p= person.rank
Output:
Yoda,Obi-Wan,Anakin
master,master,knight
Upvotes: 1
Views: 1682
Reputation: 3242
The =
character after the tag p
is for buffered code. Any JavaScript expression is valid input and will be converted to a string before being printed.
So when you put in an array, it is converted to the string representation of that array which is to separate each element with a comma.
Add a .join(" ")
after each array to convert them to a string yourself and delimit them by space rather than comma:
each person, rank in {starWars}
p= person.people.join(" ")
p= person.rank.join(" ")
Output with my changes:
Yoda Obi-Wan Anakin
master master knight
Upvotes: 3