Created
January 2, 2013 14:58
-
-
Save hitecherik-gist/4435113 to your computer and use it in GitHub Desktop.
JS: returnLast() (returns last in array)
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
| /** | |
| * Created by Alexander Nielsen. alex@hitecherik.site11.com | |
| * 2 January 2013 | |
| */ | |
| /** | |
| * Returns the last item in an array | |
| * @param {Array} arr Array to return last of | |
| * @return {var} The last item in the array | |
| */ | |
| function returnLast(arr){ | |
| var lastIndex = arr.length - 1; | |
| return arr[lastIndex]; | |
| } | |
| // example of use | |
| var myArray = [1, 2, 10, 400, 50, 98, 43]; //array of 7 integers | |
| var lastItem = returnLast(myArray); //in this case 43 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment