Archive for May 17, 2007

JavaScript Array For Loop Example

Posted in JavaScript, Software, Web, internet, programming on May 17, 2007 by Joey

The following code example demonstrates how to loop over a JavaScript array:

var aryTest = [1,2,3,4];
for (i=0;i<aryTest.length;i++)
document.write(aryTest[i]);

The length property of the JavaScript Array object is used to determine how many elements are in the array. These elements are then looped over, one-by-one, until all elements have been used, at which point the loop stops.

Related articles:
JavaScript Arrays Summary and Reference

JavaScript Array Length Property
JavaScript For Loop Example