Created
July 2, 2017 15:50
-
-
Save AJamesPhillips/a18b89b00b92840426b7231afa058220 to your computer and use it in GitHub Desktop.
JavaScript array last function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Similar to Ruby array `last` method | |
Object.defineProperty(Array.prototype, "last", { | |
get: function(){ | |
return this.length && this[this.length-1]; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment