Maxime
Maxime

Reputation: 357

How can I add a character after each word in an array except the last one in a v-for loop in a vuejs application ? Separating words with a semicolon

I would like to separate some words with a semicolon. If I do it like this

<span v-for="(item, itemIndex) in arrayOfStrings"
     :key="itemIndex"
     v-html="item + ';'" />

the last word will also have a semicolon. How can I avoid the semicolon after the last word ?

Upvotes: 0

Views: 23

Answers (1)

Maxime
Maxime

Reputation: 357

Use the join method

<span v-else>{{ arrayOfStrings.join("; ") }}</span>

Upvotes: 1

Related Questions