Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active December 17, 2015 00:29
Show Gist options
  • Save dmiro/5521573 to your computer and use it in GitHub Desktop.
Save dmiro/5521573 to your computer and use it in GitHub Desktop.
Return last element of array
// return last element of array
Array.prototype.last = Array.prototype.last || function() {
var l = this.length;
return this[l-1];
}
@dmiro
Copy link
Author

dmiro commented May 5, 2013

Example:

var miArray = [1,2,3];
console.log(miArray.last());
// return 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment