Modify Array Element

Array elements are accessed using their index number:


Array indexes start with 0:

[0] is the first array element

[1] is the second

[2] is the third ...

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Hamza",18,"Male","BCA"];
    document.write(a + "<br>");
    a[0] = "Umar";
    document.write(a + "<br>");
    a[1] = 20;
    document.write(a + "<br>");
  </script>
</head>
<body>
</body>
</html>

Delete Array Element

Array elements can be deleted using the JavaScript operator delete.

Using delete leaves undefined holes in the array.

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Hamza",18,"Male","BCA"];
    document.write(a + "<br>");
    a[0] = "Umar";
    document.write(a + "<br>");
    delete a[1];
    document.write(a + "<br>");
  </script>
</head>
<body>

</body>
</html>