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.
Object | Length value |
AnchorArray | The number of named anchors in a document |
AppletArray | The number of applets installed in a document |
Arguments | The number of arguments presented to a function when it was called |
Array | One greater than the highest numbered index in an array |
Attributes | The size of the complete set of HTML tag attributes defined for an HTML Element object |
CharacterData | The length in characters of a DOM character data node |
Collection | One greater than the highest numbered index in a collection |
Date | The number of arguments expected (always 7) |
EmbedArray | The number of plugins installed into a document |
Filters | The number of filters stacked up on a displayable object in MSIE |
Form | The number of input elements in a form |
Form.elements | The number of input elements in a form |
FormArray | The number of forms in a document |
FormElementsArray | The number of input elements in a form |
FrameArray | The number of frames in a frameset |
Frames | The number of frames in a frameset, window or iframes in a document |
Function | The number of arguments expected by a function |
History | The length of the historical record of pages visited |
ImageArray | The number of images in a document |
JavaArray | The length of a Java array encapsulated by JavaScript |
JavaObject | The number of MIME types supported by a plugin encapsulated in a JavaObject |
LayerArray | The number of layers in a document |
LinkArray | The number of HREF links in a document |
MimeTypeArray | The number of discrete MIME types that the browser supports |
NamedNodeMap | The number of named DOM nodes in a node map. |
NodeList | The size of a DOM node collection |
OptionsArray | The range of options in a popup menu |
Plugin | The number of MIME types supported by a plugin |
PluginArray | The variety of plugins currently installed in the browser |
ScriptArray | The number of script blocks in a document |
Select | The range of options in a popup menu |
SelectorArray | The number of rules in a style sheet |
String | The length of a string in characters |
style | The number of individual style components in a style rule |
styleSheets | The number of style sheets called in by the document |
textNode | The length of a textNode in characters |
Window | The 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 |
Prev | Home | Next |
Legend.padding | Up | Length units |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |