()
static
Array
()
(
o
,
startIdx
,
arraylike
)
Y.Array(o) returns an array:
- Arrays are return unmodified unless the start position is specified.
- "Array-like" collections (@see Array.test) are converted to arrays
- For everything else, a new array is created with the input as the sole
item.
- The start position is used if the input is or is like an array to return
a subset of the collection.
- Parameters:
-
o <object>the item to arrayify. -
startIdx <int>if an array or array-like, this is the start index. -
arraylike <boolean>if true, it forces the array-like fork. This can be used to avoid multiple Array.test calls.
- Returns:
Array - the resulting array.
each
static
YUI
each
(
a
,
f
,
o
)
Executes the supplied function on each item in the array.
- Parameters:
-
a <Array>the array to iterate. -
f <Function>the function to execute on each item. The function receives three arguments: the value, the index, the full array. -
o <object>Optional context object.
- Returns:
YUI - the YUI instance.
hash
static
object
hash
(
k
,
v
)
Returns an object using the first array as keys, and
the second as values. If the second array is not
provided the value is set to true for each.
- Parameters:
-
k <Array>keyset. -
v <Array>optional valueset.
- Returns:
object - the hash.
indexOf
static
int
indexOf
(
a
,
val
)
Returns the index of the first item in the array
that contains the specified value, -1 if the
value isn't found.
- Parameters:
-
a <Array>the array to search. -
val <any>the value to search for.
- Returns:
int - the index of the item that contains the value or -1.
numericSort
static
void
numericSort
(
a
,
b
)
Numeric sort convenience function.
Y.ArrayAssert.itemsAreEqual([1,2,3], [3,1,2].sort(Y.Array.numericSort));
- Parameters:
-
a <number>a number. -
b <number>a number.
some
static
boolean
some
(
a
,
f
,
o
)
Executes the supplied function on each item in the array.
Returning true from the processing function will stop the
processing of the remaining items.
- Parameters:
-
a <Array>the array to iterate. -
f <Function>the function to execute on each item. The function receives three arguments: the value, the index, the full array. -
o <object>Optional context object.
- Returns:
boolean - true if the function returns true on any of the items in the array.
test
static
int
test
(
o
)
Evaluates the input to determine if it is an array, array-like, or
something else. This is used to handle the arguments collection
available within functions, and HTMLElement collections
- Parameters:
-
o <object>the object to test.
- Returns:
int - a number indicating the results: 0: Not an array or an array-like collection 1: A real array. 2: array-like collection.