Created
July 21, 2020 14:04
-
-
Save bobdobbalina/3204f2e9255c637f81dd646999a741a8 to your computer and use it in GitHub Desktop.
Javascript: Get Last Items in an 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
| let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | |
| console.log(array.slice(-1)); // Result: [9] | |
| console.log(array.slice(-2)); // Result: [8, 9] | |
| console.log(array.slice(-3)); // Result: [7, 8, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment