get the second to last item of an array?

Not everything has to be done using jQuery.

In plain old javascript you can do:

var pg_url = array_fragment[array_fragment.length - 2]

Easier and faster :)


Looks like you can also use Javascript's slice method:

var path = 'a/b/c/d';
path.split('/').slice(-2, -1)[0]; // c

You can also think of "second to last element in the array" as "second element of the array reversed":

var path = 'a/b/c/d';
path.split('/').reverse()[1]; // c