+2 votes
in JavaScript by

How to create an array in js and how to read array elements?

1 Answer

0 votes
by

Can you define arrays using the array literal as follows?

  • var x = [];
  • var y = [1, 2, 3, 4, 5];

An array has a length property that is useful for iteration. Can we read elements of an array as follows?

for (var i = 0; i < x.length; i++)
...