I'm looking to remove the comma from the last element in Vue, but I'm unsure how to do so since the index of the last element is unknown.
<td v-if="category.sub_category.length > 0">
<template v-for="cat in category.sub_category">
{{ addComma(cat.subcategory_name) }}
</template>
</td>
addComma(subCat) {
let elements = [];
elements.push(subCat);
console.log(elements);
if (elements != ""){
elements += ", ";
}
return elements;
},
Here's the output of console.log(elements)
mentioned earlier.
https://i.sstatic.net/DXGwq.png
Below are the results of the code provided above.