Return to Kroll Design home page

JavaScript Tutorials

 
« Return

length property (arrays)

To determine the length of an array, that is, to determine how many elements the array currently contains, look at the "length" property of the array.

Code:

<script type="text/javascript">
//<![CDATA[
var colors = new Array("red", "orange", "yellow", "green", "blue", "indigo", "violet");

document.write("colors.length : ", colors.length, "<br><br>");

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

poppedElement = colors.pop();

document.write("<br>poppedElement : ", poppedElement, "<br><br>");

document.write("colors.length : ", colors.length, "<br><br>");

for (i=0; i<colors.length; i++)
{
  document.write("colors[", i, "] : ", colors[i], "<br>");
}
//]]>
</script>

Output:



 
« Return


©2012 Kroll Design    info@KrollDesign.net    781.910.3694
Last modified: 12/31/1969 7:00 PM