Built-In Class Array
A built-in class for expressing ordered lists of values.
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
Array.__iterator__()
Define an array iterator.
|
|
append(items)
Append a list of items from an array onto the end of this array
|
|
|
clean(empty)
Clean out all undefined and null values inside of an array
if false is passed to empty then only undefined items are cleaned
if true is passed to empty then empty strings will also be cleaned
|
|
|
clear()
Clear an array of all items
|
|
|
diff(otherArray)
Compare this array with another one and return an array with all the items
in this one that are not in the other.
|
|
| <native JS1.6+> |
every(fun, thisp)
Tests whether all elements in the array pass the test implemented by the provided function.
|
| <static> |
Array.fill(size, value)
Create a new array of a specified length filled with a certain value
|
| <native JS1.6+> |
filter(fun, thisp)
Creates a new array with all elements that pass the test implemented by the provided function
|
|
flat()
Returns a new version of this array which has been flattened
Flattening turns an array like [[1,2,3], [4,5,6], [7,8,9]];
into one like [1,2,3,4,5,6,7,8,9];
|
|
| <native JS1.6+> |
forEach(fun, thisp)
Executes a provided function once per array element
|
|
has(item)
Check if the array contains an item
|
|
| <native JS1.6+> |
indexOf(elt, from)
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
|
|
intersect(otherArray)
Compare this array with another one and return an array with all the items
that are in both arrays.
|
|
|
item(i)
Return an item from an index in the array
This is provided for client-side convenience so you have the same technique
for getting an item on both an array and a list of html nodes.
|
|
| <native JS1.6+> |
lastIndexOf(elt, from)
Returns the last index at which a given element can be found in the array,
or -1 if it is not present.
|
| <native JS1.6+> |
map(fun, thisp)
Creates a new array with the results of calling a provided function on every element in this array
|
|
rand()
Return a random item from this array.
|
|
| <native JS1.8+> |
reduce(fun, initial)
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
|
|
reduceNative(Function)
A version of array.reduce() which only passes the two values to reduce on
to the callback so you can use native methods like Math.max inside a reduce.
|
|
| <native JS1.8+> |
reduceRight(fun, initial)
Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
|
|
remove(item, max)
Remove the first (or more) occurrence(s) of an item from the array
|
|
|
repeat(num)
Return a new array with the contents of this array repeated over
`num` amount of times.
|
|
|
shuffle()
Shuffle the array
|
|
| <native JS1.6+> |
some(fun, thisp)
Tests whether some element in the array passes the test implemented by the provided function.
|
|
unique()
Return an array where all duplicate items have been removed
|
Method Detail
<static>
Array.__iterator__()
Define an array iterator.
Using this we never need to hide properties from loops and both for and
for each loop syntax become available for looping over arrays while
guaranteeing that they will also always iterate in order.
Defined in: Array.iterator.js.
Defined in: Array.iterator.js.
for each ( var item in [1, 2, 3] ) print(item); // Prints 1 then 2 then 3
for ( var key in [1, 2, 3] ) print(key); // Prints 0 then 1 then 2
append(items)
Append a list of items from an array onto the end of this array
- Parameters:
- items
- Array The array of items to append to this array
clean(empty)
Clean out all undefined and null values inside of an array
if false is passed to empty then only undefined items are cleaned
if true is passed to empty then empty strings will also be cleaned
- Parameters:
- {Boolean} empty Optional, Default: undefined
- Whether to also clean out empty strings or to not clear out nulls
clear()
Clear an array of all items
{Array}
diff(otherArray)
Compare this array with another one and return an array with all the items
in this one that are not in the other.
Defined in: Array.old.js.
Defined in: Array.old.js.
- Parameters:
- {Array} otherArray
- The array to compare to
- Returns:
- {Array} An array with all items in this array not in otherArray
<native JS1.6+>
{Boolean}
every(fun, thisp)
Tests whether all elements in the array pass the test implemented by the provided function.
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- {Function} fun
- Function to test for each element
- thisp Optional
- Object to use as this when executing callback
- Returns:
- {Boolean} Boolean indicating whether all elements in the array passed or not
<static>
Array.fill(size, value)
Create a new array of a specified length filled with a certain value
- Parameters:
- {Number} size
- The size of the array to create
- value Optional, Default: undefined
- The value to populate all the items in the array with
<native JS1.6+>
{Array}
filter(fun, thisp)
Creates a new array with all elements that pass the test implemented by the provided function
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- {Function} fun
- Function to test each element of the array
- thisp Optional
- Object to use as this when executing callback
- Returns:
- {Array} New array with all elements that passed
{Array}
flat()
Returns a new version of this array which has been flattened
Flattening turns an array like [[1,2,3], [4,5,6], [7,8,9]];
into one like [1,2,3,4,5,6,7,8,9];
- Returns:
- {Array} The new flattened array
<native JS1.6+>
forEach(fun, thisp)
Executes a provided function once per array element
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- {Function} fun
- Function to execute for each element
- thisp Optional
- Object to use as this when executing callback
{Boolean}
has(item)
Check if the array contains an item
- Parameters:
- {Number} item
- The item to look for
- Returns:
- {Boolean} Whether or not the item was found within the array
<native JS1.6+>
{Number}
indexOf(elt, from)
Returns the first index at which a given element can be found in the array, or -1 if it is not present.
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- elt
- Element to locate in the array
- {Number} from Optional, Default: 0
- The index at which to begin the search
- Returns:
- {Number} The index of the first occurence of the element or -1 if not found
{Array}
intersect(otherArray)
Compare this array with another one and return an array with all the items
that are in both arrays.
Defined in: Array.old.js.
Defined in: Array.old.js.
- Parameters:
- {Array} otherArray
- The array to compare to
- Returns:
- {Array} An array with all items in this array and otherArray
item(i)
Return an item from an index in the array
This is provided for client-side convenience so you have the same technique
for getting an item on both an array and a list of html nodes.
- Parameters:
- {Number} i
- The index to return the item from
<native JS1.6+>
{Number}
lastIndexOf(elt, from)
Returns the last index at which a given element can be found in the array,
or -1 if it is not present. The array is searched backwards, starting at fromIndex.
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- elt
- Element to locate in the array
- {Number} from Optional, Default: 0
- The index at which to begin the search
- Returns:
- {Number} The index of the last occurence of the element or -1 if not found
<native JS1.6+>
{Array}
map(fun, thisp)
Creates a new array with the results of calling a provided function on every element in this array
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- {Function} fun
- Function that produces an element of the new Array from an element of the current one
- thisp Optional
- Object to use as this when executing callback
- Returns:
- {Array} New array with the collected results
rand()
Return a random item from this array.
- Returns:
- A random item from the array
<native JS1.8+>
reduce(fun, initial)
Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
Defined in: Array18.js.
Defined in: Array18.js.
- Parameters:
- {Function} fun
- Function to execute on each value in the array
- initial Optional
- Object to use as the first argument to the first call of the callback
- Returns:
- The final value created by the reduce
reduceNative(Function)
A version of array.reduce() which only passes the two values to reduce on
to the callback so you can use native methods like Math.max inside a reduce.
- Parameters:
- Function
- fn The callback function
<native JS1.8+>
reduceRight(fun, initial)
Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
Defined in: Array18.js.
Defined in: Array18.js.
- Parameters:
- {Function} fun
- Function to execute on each value in the array
- initial Optional
- Object to use as the first argument to the first call of the callback
- Returns:
- The final value created by the reduce
remove(item, max)
Remove the first (or more) occurrence(s) of an item from the array
- Parameters:
- item
- The item to remove
- {Number} max Optional, Default: 1
- The max number of items to remove, use Infinity to remove them all
{Array}
repeat(num)
Return a new array with the contents of this array repeated over
`num` amount of times.
- Parameters:
- {Number} num
- The number of times to repeat the array
- Returns:
- {Array} The new repeated array
{Array}
shuffle()
Shuffle the array
- Returns:
- {Array} The same array for convenience
<native JS1.6+>
{Boolean}
some(fun, thisp)
Tests whether some element in the array passes the test implemented by the provided function.
Defined in: Array16.js.
Defined in: Array16.js.
- Parameters:
- {Function} fun
- Function to test for each element
- thisp Optional
- Object to use as this when executing callback
- Returns:
- {Boolean} Boolean indicating whether some element in the array passed or not
{Array}
unique()
Return an array where all duplicate items have been removed
- Returns:
- {Array} A new array with a unique list of all items in this array