Reputation: 49
Say I have mongodb collection called "people", and the following documents are inside the people collection:
{
name: "James",
aliases: ["Jim", "Jimmy", "Jimbo", "Jamie"]
}
{
name: "Mary",
aliases: ["Mae", "May", "Molly", "Mimi"]
}
I'm trying to find a way to write the aliases array for each document in an HTML element, and also format them with spaces.
Doing this: [EDITED] I had given a bad example
<p>{{aliases}}</p>
results in listing the names like
"Jim,Jimmy,Jimbo,Jamie"
. Is there a way I can make it result in
"Jim, Jimmy, Jimbo, Jamie"
with spaces instead?
Upvotes: 3
Views: 68
Reputation: 48357
By using {{aliases}}
, the compiler will set the array
as value for innerHTML
property and the array will be automatically coerced to string
.
When we're using .toString()
method for one array
it's invoked automatically join
method with default delimiter = ','
Use this:
{{aliases.join', '}}
Syntax edited
Upvotes: 4