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