length (Property)

The length, magnitude, or size of an object depending on its type.


JavaScript - 1.0
JScript - 3.0
Internet Explorer - 4.0
Netscape - 2.0
Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-frames.length

Many objects respond to the length property accessor message. They don't all yield the same sort of value, although the value they yield will always be numeric.

For example, Window objects have a length property. In this case it will yield the number of frames in the window, and it is also available as a global variable called length.

The other objects that provide a length property don't reflect its value into so many alternative ways of accessing it. Apart perhaps from the Form.length value which is the same as the Form.elements.length value. This is necessary because the Form.elements collection is superimposed on the Form object so that you can access individual elements of the form as if they were direct member properties of the Form object. If you try to enumerate the Form object, you get lots of properties enumerated which are not form elements. You should therefore enumerate the Form.elements array.

This table lists objects which have a length property, and describes what it counts.

ObjectLength value
AnchorArrayThe number of named anchors in a document
AppletArrayThe number of applets installed in a document
ArgumentsThe number of arguments presented to a function when it was called
ArrayOne greater than the highest numbered index in an array
AttributesThe size of the complete set of HTML tag attributes defined for an HTML Element object
CharacterDataThe length in characters of a DOM character data node
CollectionOne greater than the highest numbered index in a collection
DateThe number of arguments expected (always 7)
EmbedArrayThe number of plugins installed into a document
FiltersThe number of filters stacked up on a displayable object in MSIE
FormThe number of input elements in a form
Form.elementsThe number of input elements in a form
FormArrayThe number of forms in a document
FormElementsArrayThe number of input elements in a form
FrameArrayThe number of frames in a frameset
FramesThe number of frames in a frameset, window or iframes in a document
FunctionThe number of arguments expected by a function
HistoryThe length of the historical record of pages visited
ImageArrayThe number of images in a document
JavaArrayThe length of a Java array encapsulated by JavaScript
JavaObjectThe number of MIME types supported by a plugin encapsulated in a JavaObject
LayerArrayThe number of layers in a document
LinkArrayThe number of HREF links in a document
MimeTypeArrayThe number of discrete MIME types that the browser supports
NamedNodeMapThe number of named DOM nodes in a node map.
NodeListThe size of a DOM node collection
OptionsArrayThe range of options in a popup menu
PluginThe number of MIME types supported by a plugin
PluginArrayThe variety of plugins currently installed in the browser
ScriptArrayThe number of script blocks in a document
SelectThe range of options in a popup menu
SelectorArrayThe number of rules in a style sheet
StringThe length of a string in characters
styleThe number of individual style components in a style rule
styleSheetsThe number of style sheets called in by the document
textNodeThe length of a textNode in characters
WindowThe number of frames in a window

Although the length property is marked here as ReadOnly, in some circumstances it may be useful to assign a value to it to extend, or truncate an Array object.

See also:Array.length, Form.elements.length, Form.length, Window.length

Property attributes:


insert figure 0060