Javascript: Select all but one item from array with slice()?

Viewed 5782

Let's say I have this array:

var myarray = [a, b, c, d, e];

I want to select every item in the array except c.

var myselection = myarray.slice(3,5);

This selects only d and e. I would have to do:

var myselection = myarray.slice(3,5) + myarray.slice(0,2);

This selects d, e, a and b, BUT the output is not usable as a selector, since myselection is now written without a comma in between e and a: "d,ea,b"

Do you know a way to solve this? Maybe with negative numbers?

Thanks a lot for your help!!! Lee

3 Answers
Related