Last active
February 6, 2022 18:56
-
-
Save codeBelt/7a2303c58de4252e2366138a89b68bb7 to your computer and use it in GitHub Desktop.
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
const arrayData = ['a', 'b', 'c', 'd', 'e']; |
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
/* | |
* destructuring array to object | |
*/ | |
const { ...all } = arrayData; | |
all // {0: "a", 1: "b", 2: "c", 3: "d", 4: "e"} |
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
/* | |
* destructuring array to object and renaming the index to a property name | |
*/ | |
const { 0: first, 4: last, ...rest } = arrayData; | |
first // "a" | |
last // "e" | |
rest // {1: "b", 2: "c", 3: "d"} |
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
/* | |
* destructuring array to object and renaming the index to a property name | |
* with last item being dynamic | |
*/ | |
const { 0: first, [arrayData.length - 1]: last, ...rest } = arrayData; | |
first // "a" | |
last // "e" | |
rest // {1: "b", 2: "c", 3: "d"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment