# Yahoo! UI Library

### yui 3.0.0b1

Yahoo! UI Library > yui > Array
Search:
Filters
Show Private Show Protected Show Deprecated

## Class Array

Adds the following array utilities to the YUI instance. Additional array helpers can be found in the collection component.

### Methods

#### ()

`static Array () ( o , i , al )`
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
  `i <int>` if an array or array-like, this is the start index
  `al <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
  `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 <object>` the value to search for

Returns: `int`
  the index of the item that contains the value or -1

#### numericSort

`void numericSort ( )`
Numeric sort convenience function. Y.ArrayAssert.itemsAreEqual([1, 2, 3], [3, 1, 2].sort(Y.Array.numericSort));

Returns: `void`

#### 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
  `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 ( )`
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

Returns: `int`
  a number indicating the results: 0: Not an array or an array-like collection 1: A real array. 2: array-like collection.

Copyright © 2009 Yahoo! Inc. All rights reserved.