Skip to content

Instantly share code, notes, and snippets.

@sakshstore
Created August 10, 2023 03:43
Show Gist options
  • Save sakshstore/43aaff85aca53709b87fd08249223f3d to your computer and use it in GitHub Desktop.
Save sakshstore/43aaff85aca53709b87fd08249223f3d to your computer and use it in GitHub Desktop.
Array destructuring allows you to extract individual elements from an array and assign them to separate variables.
// Longhand
const numbers = [1, 2, 3];
const firstNumber = numbers[0];
const secondNumber = numbers[1];
// Shorthand
const numbers = [1, 2, 3];
const [firstNumber, secondNumber] = numbers;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment