Heterogenous Array

An array with elements that belong to different datatypes is called Heterogenous Array.

Example

In the following example, we initialize an Array with objects of type numeric, and string values, and access its elements using index.

index.html

</>
Copy
<!doctype html>
<html>
  <body>
    <h2>JavaScript - Heterogenous Array</h2>
    <pre id="output"></pre>

    <script>
      var myArray = [28, 'apple', 2022];

      document.getElementById("output").innerHTML = myArray + '\n';
      document.getElementById("output").innerHTML += "myArray[1] : " + myArray[1];
    </script>

  </body>
</html>