Changing Elements of an Arrary



Write a JavaScript code to implement shift method of array.

<html>
  <head>
    <title>Array Demo</title>
      <script>

        var a =new Array();

            a[0]=5;
            a[1]=3;
            a[2]=4;
            a[3]=2;
            a[4]=1;

            document.write("Elements before shift...<br>");

            for(var i=0;i < a.length;i++)
            {
                document.write(a[i] + "<br>");
            }
            a.shift();
            document.write("Elements after shift...<br>");

            for(var i=0;i < a.length;i++)
            {
                document.write(a[i] + "<br>");
            }

      </script>
    </head>
  <body>       
</body>
</html>

Output:

Elements before shift...
5 3 4 2 1
Elements after shift...
3 4 2 1