Created
August 28, 2022 07:25
-
-
Save kirilkirkov/fc6e20f9cee38031753d3828386f23f8 to your computer and use it in GitHub Desktop.
JavaScript - Destructuring To Get The First And Last Element Of An Array In ES6
This file contains 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
The easiest lay to get first and last element from an array in javascript with one line code. | |
<script> | |
const meals = ['apple', 'orange', 'bananna']; | |
const {length, 0: first, [length - 1]: last} = meals; | |
console.log(first, last) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment