0

I want to add a comma between a set of strings using the .each() function except for at the end. How is it possible to get rid of that last comma?

user2512696
  • 187
  • 2
  • 5
  • 13

2 Answers2

1
$('#mySelector:not(:last)').each 

:-)

pmandell
  • 4,278
  • 16
  • 21
Nico
  • 273
  • 2
  • 11
0

FWIW, modern browsers allow you to do this with CSS, very similar to the jQuery solution:

.item:not(:last-of-type)::after {
    content: ', '
}
Tomalak
  • 322,446
  • 66
  • 504
  • 612