Readonly
lengthlength
number of elements in the array.
GetElementAt()
Retrieve a specific element of the array. null is a valid result for this method.
Note: If the index is out of bounds null will be returned. This differs from the behavior of nsIArray.queryElementAt() which will throw if an invalid index is specified.
position of element
Optional
aInstancePtr: objectA run time mechanism for interface discovery.
NS_OK if the interface is supported by the associated instance, NS_NOINTERFACE if it is not.
aInstancePtr must not be null.
[in] A requested interface IID
[out] A pointer to an interface pointer to receive the result.
enumerate the array
a new enumerator positioned at the start of the array
NS_ERROR_FAILURE if the array is empty (to make it easy to detect errors), or NS_ERROR_OUT_OF_MEMORY if out of memory.
indexOf()
Get the position of a specific element. Note that since null is a valid input, exceptions are used to indicate that an element is not found.
a number >= startIndex which is the position of the element in the array.
NS_ERROR_FAILURE if the element was not in the array.
The initial element to search in the array To start at the beginning, use 0 as the startIndex
The element you are looking for
insertElementAt()
Insert an element at the given position, moving the element currently located in that position, and all elements in higher position, up by one.
The element to insert
The position in the array: If the position is lower than the current length of the array, the elements at that position and onwards are bumped one position up. If the position is equal to the current length of the array, the new element is appended. An index lower than 0 or higher than the current length of the array is invalid and will be ignored.
queryElementAt()
Retrieve a specific element of the array, and QueryInterface it to the specified interface. null is a valid result for this method, but exceptions are thrown in other circumstances
NS_ERROR_NO_INTERFACE when an entry exists at the specified index, but the requested interface is not available.
NS_ERROR_ILLEGAL_VALUE when index > length-1
position of element
the IID of the requested interface
the object, QI'd to the requested interface
removeElementAt()
Remove an element at a specific position, moving all elements stored at a higher position down one. To remove a specific element, use indexOf() to find the index first, then call removeElementAt().
the position of the item
replaceElementAt()
Replace the element at the given position.
The new element to insert
The position in the array If the position is lower than the current length of the array, an existing element will be replaced. If the position is equal to the current length of the array, the new element is appended. If the position is higher than the current length of the array, empty elements are appended followed by the new element at the specified position. An index lower than 0 is invalid and will be ignored.
Generated using TypeDoc
nsIMutableArray A separate set of methods that will act on the array. Consumers of nsIArray should not QueryInterface to nsIMutableArray unless they own the array.
As above, it is legal to add null elements to the array. Note also that null elements can be created as a side effect of insertElementAt(). Conversely, if insertElementAt() is never used, and null elements are never explicitly added to the array, then it is guaranteed that queryElementAt() will never return a null value.
Any of these methods may throw NS_ERROR_OUT_OF_MEMORY when the array must grow to complete the call, but the allocation fails.