How to assign undefined value to an array element in JavaScript

 
Following example shows that how to assign undefined value to an array element in JavaScript.

<HTML>
   <HEAD>
   <TITLE>
     undefined element in javaScript array
   </TITLE>
   </HEAD>
   <BODY>
   <SCRIPT>
      var ArrayCity = new Array(4);
         ArrayCity[0] = "New Delhi";
         ArrayCity[1] = "NewYork";
         ArrayCity[2] =  undefined;
         ArrayCity[3] = "Kolkata";
 
     for (var i = 0; i < ArrayCity.length; i++){
       if (ArrayCity[i] != undefined)
        document.write("ArrayCity[" + i + "] = " + ArrayCity[i] + "<br>");
     }     
   </SCRIPT>
   </BODY>
</HTML>

Output of above example will be:

ArrayCity[0] = New Delhi
ArrayCity[1] = NewYork
ArrayCity[3] = Kolkata