How to convert a node list to an array in JavaScript?

Following is the code to convert a node list to an array 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;
   .sample {
      display: inline-block;
      font-size: 20px;
      font-weight: 500;
      color: white;
      background-color: blue;
      width: 100px;
      height: 100px;
<h1>Convert a node list to an array</h1>
<div class="sample">1</div>
<div class="sample">2</div>
<div class="sample">3</div>
<div class="sample">4</div>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to change colors of all the above div </h3>
   let sampEle = document.querySelectorAll('.sample');
   let BtnEle = document.querySelector('.Btn');
      Array.from(sampEle).forEach(item=>{ = 'red';


On clicking the ‘CLICK HERE’ button −