Multiple choice

What will be the output of the above code?

var arr = new Array();
arr[0] = "Element 1";
arr[1] = "Element 2";
arr[2] = "Element 3";
arr[3] = "Element 4";
document.write(arr[0, 1, 2, 3]);

  1. Error

  2. Element 1

  3. Element 4

  4. Element 1, Element 2, Element 3, Element 4

  5. No output (blank screen)

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The result will be Element 4. The other elements will not be printed. To print all the values of the array a loop can be used.