Array De-structuring in JavaScript.

Destructuring unpacks values from an array. Following is the code for array de-structuring in JavaScript −


 Live Demo

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   .result,.sample {
      font-size: 20px;
      font-weight: 500;
<h1>Array De-structuring in JavaScript</h1>
<div class="sample"></div>
<div style="color: green;" class="result"></div>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to destructure the above array</h3>
   let sampleEle = document.querySelector(".sample");
   let resEle = document.querySelector(".result");
   let arr = ["F", "G", 22, 44];
   sampleEle.innerHTML = "arr = " + arr;
   let a, b, c, d;
   document.querySelector(".Btn").addEventListener("click", () => {
      [a, b, c, d] = arr;
      resEle.innerHTML = "After destructuring array :<br> ";
      resEle.innerHTML += `a=${a} b=${b} c=${c} d=${d}`;


The above code will produce the following output −

On clicking the ‘CLICK HERE’ button −