selecting the last item of an arry javascript code example
Example 1: javascript code for find the last element in array
if (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}
Example 2: javascript array last element
var lastEle = arr.slice(-1)[0];
// or
var lastEle = arr.slice(-1).pop();