I'll suggest to create helper function and reuse it every time, you'll need it. Lets make function more general to be able to get not only last item, but also second from the last and so on.
function last(arr, i) {
var i = i || 0;
return arr[arr.length - (1 + i)];
}
Usage is simple
var arr = [1,2,3,4,5];
last(arr); //5
last(arr, 1); //4
last(arr, 9); //undefined
Now, lets solve the original issue
Grab second to last item form array. If the last item in the loc_array is "index.html" grab the third to last item instead.
Next line does the job
last(loc_array, last(loc_array) === 'index.html' ? 2 : 1);
So, you'll need to rewrite
var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2])));
in this way
var newT = document.createTextNode(unescape(capWords(last(loc_array, last(loc_array) === 'index.html' ? 2 : 1))));
or use additional variable to increase readability
var nodeName = last(loc_array, last(loc_array) === 'index.html' ? 2 : 1);
var newT = document.createTextNode(unescape(capWords(nodeName)));