Inheritance diagram for Array:
Properties | |
Number | length |
Constructors | |
Array (Object firstElement[,...]) | |
Array (Number len) | |
Array () | |
Methods (ECMAScript) | |
Array | concat (Object element1[,...]) |
String | join (String separator=",") |
Object | pop () |
Number | push (Object element1[,...]) |
Array | reverse () |
Object | shift () |
Array | slice (Number startIndex, Number endIndex=length) |
Array | sort (function comparisonFunction) |
Array | splice (Number startIndex, Number replacementCount[,...]) |
String | toLocaleString () |
String | toString () |
Array | unshift (Object element1[,...]) |
Methods (DAZ Script 2 Extensions) | |
Number | find (Object element) |
Number | pushIfNotExists (Object element1[,...]) |
An Array is a data type that allows you to work with a list of elements. These elements can be any QObject derived object. Multi-dimensional arrays are achieved by using array elements that are arrays themselves.
var aTmp = [];
var aTmp = [ "a", "b", "c", "d" ];
new
operator, initialized with a size, but with undefined elementsvar aTmp = new Array( 4 );
new
operator, defining all elementsvar aTmp = new Array( "a", "b", "c", "d" );
var aTmp = new Array( "a", "b", "c", "d" ); var aTmp2 = new Array; // aTmp2 == [] for ( var i = 0; i < aTmp.length; i++ ) { aTmp2[ i ] = new Array( 2 ); aTmp2[ i ][ 0 ] = i; aTmp2[ i ][ 1 ] = aTmp[ i ]; } // aTmp2 == [ [ 0, "a" ], [ 1, "b" ], [ 2, "c" ], [ 3, "d" ] ]
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = aTmp[ 2 ]; // sTmp == "c";
var aTmp = new Array( [ "a", 5 ], [ "b", 10 ], [ "c", 15 ], [ "d", 20 ] ); var nTmp = aTmp[ 2 ][ 1 ]; // nTmp == 15;
var aTmp = []; // Assignment: aTmp[ "one" ] = "a"; aTmp[ "two" ] = "b"; // Retrieval: var sTmp = aTmp[ "one" ]; // sTmp == "a" var sTmp2 = aTmp[ "two" ]; // sTmp2 == "b"
var aTmp = []; // Assignment: aTmp.one = "a"; aTmp.two = "b"; // Retrieval: var sTmp = aTmp.one; // sTmp == "a" var sTmp2 = aTmp.two; // sTmp2 == "b"
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = new String; for( var i = 0; i < aTmp.length; i++ ){ sTmp += aTmp[ i ]; } // sTmp == "abcd"
var aTmp = new Array; aTmp[ "first" ] = "a"; aTmp[ "second" ] = "b"; aTmp[ "third" ] = "c"; aTmp[ "fourth" ] = "d"; // element names are sorted alphanumericically // aTmp == [ "first" : "a", "fourth" : "d", "second" : "b", "third" : "c" ] var sTmp = new String; for( var i in aTmp ){ sTmp += aTmp[ i ]; } // sTmp == "adbc"
Array::Array | ( | ) |
Array::Array | ( | Number | len | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructs an array of the given length. The arrays elements will be uninitialized (undefined).
len | The number of items in the new array |
Array::Array | ( | Object | firstElement[,...] | ) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Constructs an array with one or more elements
firstElement | The first element to add to the array. | |
... | Additional elements to add to the array. (Optional) |
element1 | The first element to concatenate with the array. | |
... | Additional elements to concatenate with the array. (Optional) |
var aTmp = new Array( "a", "b", "c" ); var nTmp = 5; var aTmp2 = aTmp.concat( nTmp ); // aTmp == [ "a", "b", "c" ] // aTmp2 == [ "a", "b", "c", 5 ]
element | The item to search for in the array |
element
, if found. -1 if element
is not found.var aTmp = new Array( "a", "b", "c", "d", "e" ); var nTmp = aTmp.find( "d" ); // nTmp == 3
separator | The character used to separate the elements in the list |
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = aTmp.join( ":" ); // sTmp == "a:b:c:d"
Object Array::pop | ( | ) |
Removes the last (right-most) element from the array.
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = aTmp.pop(); // aTmp == [ "a", "b", "c" ] // sTmp == "d"
element1 | The first element to append to the array. | |
... | Additional elements to append to the array. (Optional) |
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.push( "e" ); // aTmp == [ "a", "b", "c", "d", "e" ]
element1 | The first element to append to the array. | |
... | Additional element(s) to insert into the array. (Optional) Pushes one or more elements onto the end (right) of the array, if it doesn't already exist in the array. |
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.pushIfNotExists( "e" ); // aTmp == [ "a", "b", "c", "d", "e" ]
Array Array::reverse | ( | ) |
Reverses the order of the elements in the array.
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.reverse(); // aTmp == [ "d", "c", "b", "a" ]
var aTmp = new Array( "a", "b", "c", "d" ); var aTmp2 = aTmp; aTmp.reverse(); // aTmp == [ "d", "c", "b", "a" ] // aTmp2 == [ "d", "c", "b", "a" ]
Object Array::shift | ( | ) |
Removes the first (left-most) element in the array.
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = aTmp.shift(); // aTmp == [ "b", "c", "d" ] // sTmp == "a"
startIndex | The index of the first element in the slice. | |
endIndex | The index of the element to end the slice at. Defaults to the length of the array. (Optional) |
startIndex
to (but not including) the element at endIndex
.var aTmp = new Array( "a", "b", "c", "d", "e", "f" ); var aTmp2 = aTmp.slice( 2 ); // aTmp == [ "a", "b", "c", "d", "e", "f" ] // aTmp2 == [ "c", "d", "e", "f" ]
var aTmp = new Array( "a", "b", "c", "d", "e", "f" ); var aTmp2 = aTmp.slice( 1, 4 ); // aTmp == [ "a", "b", "c", "d", "e", "f" ] // aTmp2 == [ "b", "c", "d" ]
Array Array::sort | ( | function | comparisonFunction | ) |
Sorts the array using comparisonFunction
. If no function is provided, default sorting is applied.
comparisonFunction | The function to call to compare items in the array. (Optional) |
var aTmp = new Array( "a", "c", "d", "b" ); aTmp.sort(); // aTmp == [ "a", "b", "c", "d" ]
// -1 if a < b, 0 if a == b, 1 if a > b function numerically( a, b ){ return a < b ? -1 : a > b ? 1 : 0; } var aTmp = new Array( 8, 90, 1, 4, 843, 221 ); aTmp.sort( numerically ); // aTmp == [ 1, 4, 8, 90, 221, 843 ]
Splices elements into the array.
startIndex | The index in the array to place the new element(s). | |
replacementCount | The number of elements in the array to replace. | |
... | The element(s) to insert into the array. (Optional) |
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.splice( 2, 0, "X" ); // aTmp == [ "a", "b", "X", "c", "d" ]
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.splice( 2, 0, "X", "Y" ); // aTmp == [ "a", "b", "X", "Y", "c", "d" ]
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.splice( 2, 1 ); // aTmp == [ "a", "b", "d" ]
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.splice( 2, 1, "X" ); // aTmp == [ "a", "b", "X", "d" ]
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.splice( 2, 1, "X", "Y" ); // aTmp == [ "a", "b", "X", "Y", "d" ]
String Array::toLocaleString | ( | ) |
Provides a locale-aware version of toString()
Reimplemented from Object.
String Array::toString | ( | ) |
var aTmp = new Array( "a", "b", "c", "d" ); var sTmp = aTmp.toString(); // sTmp == "a,b,c,d"
Reimplemented from Object.
Inserts the element(s) at the beginning (left) of the array.
element1 | The first element to insert into the array. | |
... | Additional element(s) to insert into the array. (Optional) |
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.unshift( "X" ); // aTmp == [ "X", "a", "b", "c", "d" ]
var aTmp = new Array( "a", "b", "c", "d" ); aTmp.unshift( "X", "Y" ); // aTmp == [ "X", "Y", "a", "b", "c", "d" ]
The number of elements in the array.
var aTmp = new Array( "a", "b", "c", "d" ); var nTmp = aTmp.length; // nTmp == 4