Array demonstration
JavaScript code
Note: Use of document.write() and document.writeln()
for normal use is discouraged - but it works for what we
want here.
var a = new Array();
a[0] = 7;
a[5] = "Dave";
document.writeln('Length of a[] is ' + a.length + '<br>');
document.writeln('Display of array elements using traditional for loop:<br>');
for (var i=0; i<a.length; i++) {
document.writeln('a[' + i + '] = ' + a[i] + '<br>');
}
document.writeln('Display of array elements using for/in loop:<br>');
for (var ndx in a) {
document.writeln('a[' + ndx + '] = ' + a[ndx] + + '<br>');
}
Results of JavaScript code