API Docs for: 0.0.1
Show:

Array Class

Module: lib/array.js
Parent Module: js-ext

Pollyfils for often used functionality for Arrays Copyright (c) 2014 ITSA - https://github.com/itsa New BSD License - http://choosealicense.com/licenses/bsd-3-clause/

Methods

concatMerge

(
  • array
  • [prepend=false]
  • [clone=false]
  • [descriptors=false]
)
chainable

Merges array into this array (appended by default).

Parameters:

  • array Array

    the Array to be merged

  • [prepend=false] Boolean optional

    whether the items prepended

  • [clone=false] Boolean optional

    whether the items should be cloned

  • [descriptors=false] Boolean optional

    whether to use the descriptors when cloning

contains

(
  • item
)
Boolean

Checks whether an item is inside the Array. Alias for (array.indexOf(item) > -1)

Parameters:

  • item Any

    the item to seek

Returns:

Boolean:

whether the item is part of the Array

deepClone

(
  • [descriptors=false]
)
Array

Returns a deep copy of the Array. Only handles members of primary types, Dates, Arrays and Objects.

Parameters:

  • [descriptors=false] Boolean optional

    whether to use the descriptors when cloning

Returns:

Array:

deep-copy of the original

defineData

(
  • array
  • [clone=false]
)
chainable

Sets the items of array to the instance. This will refill the array, while remaining the instance. This way, external references to the array-instance remain valid.

Parameters:

  • array Array

    the Array that holds the new items.

  • [clone=false] Boolean optional

    whether the items should be cloned

empty

() chainable

Empties the Array by setting its length to zero.

insertAt

(
  • item
  • index
  • [duplicate=false]
)
chainable

Inserts an item in the array at the specified position. If index is larger than array.length, the new item(s) will be appended. If the item already exists, it will be moved to its new position, unless duplicate is set true

Parameters:

  • item Any | Array

    the item to be replaced, may be an Array of items

  • index Number

    the position where to add the item(s). When larger than Array.length, the item(s) will be appended.

  • [duplicate=false] Boolean optional

    if an item should be duplicated when already in the array

observe

() chainable

Provided by the lib/object.js module.

Defined in src/js-ext/extra/observers.js:216

Observes changes of the instance. On any changes, the callback will be invoked. Uses a polyfill on environments that don't support native Array.observe.

The callback comes without arguments (native Array.observe does, but non-native doesn't) so, they cannot be used.

Will observer the complete array nested (deep).

remove

(
  • item
  • [arrayItem=false]
)
chainable

Removes an item from the array

Parameters:

  • item Any | Array

    the item (or an hash of items) to be removed

  • [arrayItem=false] Boolean optional

    whether item is an arrayItem that should be treated as a single item to be removed You need to set arrayItem=true in those cases. Otherwise, all single items from item are removed separately.

replace

(
  • prevItem
  • newItem
)
chainable

Replaces an item in the array. If the previous item is not part of the array, the new item is appended.

Parameters:

  • prevItem Any

    the item to be replaced

  • newItem Any

    the item to be added

sameValue

(
  • refObj
)
Boolean

Compares this object with the reference-object whether they have the same value. Not by reference, but their content as simple types.

Compares both JSON.stringify objects

Parameters:

  • refObj Object

    the object to compare with

Returns:

Boolean:

whether both objects have the same value

shuffle

() chainable

Shuffles the items in the Array randomly

unobserve

() chainable

Provided by the lib/object.js module.

Defined in src/js-ext/extra/observers.js:273

Un-observes changes that are registered with observe. Uses a polyfill on environments that don't support native Array.observe.