API Docs for: 1.0.1

Grape.Array Class

An array class created with Grape.Class mixing all of the Array.prototype methods and some new utility. Some functions are modified (like slice) to return a new instance of the current class instead of a plain array. If you extend this class, these methods will return an instance of your class. In the future, we should create implementations of default methods for old browsers. Note that adding elements with indexing does not change the length property unlike the native Array.

Constructor

Grape.Array

()

Methods

apply

(
  • which
  • params
)
Grape.Array

Calls a method of each item, but the parameters are passed as an array like in Function.prototype.apply

Parameters:

  • which String

    The method name to call

  • params Array

    The method parameters

Returns:

Grape.Array:

this

attr

(
  • name
  • newVal
)
Grape.Array

Sets an attribute on each item.

Parameters:

  • name String

    The attribute name

  • newVal

    The new value of the attribute

Returns:

Grape.Array:

this

call

(
  • which
)
Grape.Array

Calls a method of each item. The subsequent parameters are passed to the method.

Parameters:

  • which String

    The method name to call

Returns:

Grape.Array:

this

clone

()

Clones the array (shallow copy) by creating a new instance of the current class.

Returns:

:

The cloned array

eq

(
  • i
)
Grape.Array

Creates a new instance of the current class, containing the item at the index i if exists, or an empty array

Parameters:

  • i Number

    The index

Returns:

Grape.Array:

The array containing 0 or 1 item

get

(
  • i
)

Returns an item at the given position. Equivalent to arr[i].

Parameters:

  • i Number

    The index of the item to return

Returns:

:

The item at the given position

isEmpty

() Boolean

Returns true if the length of the array is 0.

Returns:

Boolean:

true, if length is 0

one

()

Returns one (the first) item from the array.

Returns:

:

The first item

random

(
  • num
)
Grape.Array

Returns a new instance of the current class containing random items from the original array.

Parameters:

  • num Number | Undefined

    The number of random items. If not set returns one item.

Returns:

Grape.Array:

The random items

size

() Number

Returns the length of the array.

Returns:

Number:

The size of the array

toArray

() Array

Creates a native Array by copying the items

Returns:

Array:

The native Array