Hosting Solutions
mobile_logo Table of Contents


The length property is used to count how many items or elements are in an object.


Count the amount of characters in a string string object

var str = "Hello"; alert( str.length ); /* 5 */

Count the amount of elements in an array object

var arr = ["cat","dog","bird"]; alert( arr.length ); /* 3 */ If length value is adjusted, the array will be cut down to the given length. var arr = [1,2,3,4,5,6]; arr.length = 4; /* 1,2,3,4 */

Count the amount of arguments in an arguments object

alert( arguments.length );

Count the amount of arguments expected by a function

function myFunction(a, b) { } alert( myFunction.length );

Count the amount of items in the history object

alert( history.length );

Count the amount of iframe windows embedded in a document

<iframe src=""></iframe> <iframe src=""></iframe> <script> alert( window.length ); </script>