marcamillion marcamillion - 10 months ago 52
jQuery Question

If I have an array of values, how do I join some together separated by a dash?

Say I have an array that looks like this:

array1 = button.attr('id').split('-');
["slider", "step", "value", "speed", "rebecca", "nitzsche", "st", "george", "s", "college"]

What I want to do is to take every element after
, so everything after
to the end, and mush it all into 1 string separated by a
so it looks like this:

How do I do this?

Answer Source

You can simply use slice and then join, like so:

var array = ["slider", "step", "value", "speed", "rebecca", "nitzsche", "st", "george", "s", "college"];

// It will return => "rebecca-nitzsche-st-george-s-college"