Prototype:
var array = [1,2,3,4]; var lastEl = array.last();
Anything similar to this in jQuery?
Prototype:
var array = [1,2,3,4]; var lastEl = array.last();
Anything similar to this in jQuery?
Why not just use simple javascript?
var array=[1,2,3,4];
var lastEl = array[array.length-1];
You can write it as a method too, if you like (assuming prototype has not been included on your page):
Array.prototype.last = function() {return this[this.length-1];}
with slice():
var a = [1,2,3,4];
var lastEl = a.slice(-1)[0]; // 4
// a is still [1,2,3,4]
with pop();
var a = [1,2,3,4];
var lastEl = a.pop(); // 4
// a is now [1,2,3]
see http://www.w3schools.com/jsref/jsref_obj_array.asp for more information