Array

Type module

Sources

Items from Array can be imported/included and used via following ways.

/**
 * --------------------------------------------------------
 * Import via main package: core.ts
 * Access items like: am5.array.myVariable
 *                    am5.array.myFunction()
 * --------------------------------------------------------
 */
import * as am5 from "@amcharts/amcharts5";

/**
 * --------------------------------------------------------
 * Import via: Array.ts
 * Access items like: $array.myVariable
 *                    $array.myFunction()
 * --------------------------------------------------------
 */
import * as $array from "@amcharts/amcharts5/Array";

/**
 * --------------------------------------------------------
 * Include via "index.js"
 * E.g.: "https://cdn.amcharts.com/lib/5/index.js"
 * Access items like: am5.array.myVariable
 *                    am5.array.myFunction()
 * --------------------------------------------------------
 */

Variables

Array does not have any variables.

Functions

add(

array: Array,
element: A,
index?: undefined | number

)

#

Returns void

Adds count of time unit to the source date. Returns a modified Date object.

any(

array: ArrayLike,
test: ( value: A) => boolean

)

#

Returns boolean

Calls test for each element in array.

If test returns true then it immediately returns true.

If test returns false for all of the elements in array then it returns false.

copy(

array: ArrayLike

)

#

Returns Array

Returns a copy of the Date object.

each(

array: ArrayLike,
fn: ( value: A, index: number) => void

)

#

Returns void

Iterates through all items in array and calls fn function for each of them.

eachContinue(

array: ArrayLike,
fn: ( value: A, index: number) => boolean

)

#

Returns void

Iterates through all properties of the object calling fn for each of them.

If return value of the function evaluates to false further iteration is cancelled.

eachReverse(

array: ArrayLike,
fn: ( value: A, index: number) => void

)

#

Returns void

Iterates through all items in array in reverse order and calls fn function for each of them.

find(

array: ArrayLike,
matches: ( value: A, index: number) => boolean

)

#

Returns A | undefined

Searches the array using custom function and returns item if found.

Will call matches function on all items of the array. If return value evaluates to true, index is returned.

Otherwise returns undefined.

findIndex(

array: ArrayLike,
matches: ( value: A, index: number) => boolean

)

#

Returns number

Searches the array using custom function and returns index of the item if found.

Will call matches function on all items of the array. If return value evaluates to true, index is returned.

Otherwise returns -1.

findIndexReverse(

array: ArrayLike,
matches: ( value: A, index: number) => boolean

)

#

Returns number

This is the same as findIndex except it searches from right to left.

findMap(

array: ArrayLike,
matches: ( value: A, index: number) => B | undefined

)

#

Returns B | undefined

Searches the array using custom function and returns item if found.

Will call matches function on all items of the array. If value is not undefined, it returns it.

Otherwise returns undefined.

findReverse(

array: ArrayLike,
matches: ( value: A, index: number) => boolean

)

#

Returns A | undefined

This is the same as find except it searches from right to left.

first(

array: Array

)

#

Returns Optional

Returns the first item of the array.

has(

array: ArrayLike,
element: A

)

#

Returns boolean

Returns true if element exists in array.

indexOf(

array: ArrayLike,
value: A

)

#

Returns number

Searches array for value.

Returns -1 if not found.

insert(

array: Array,
element: A,
index: number

)

#

Returns void

Inserts element into array at index.

Caps index to be between 0 and array.length

insertIndex(

array: Array,
index: number,
value: A

)

#

Returns void

Inserts a value into array at specific index.

keepIf(

array: Array,
keep: ( value: A) => boolean

)

#

Returns void

last(

array: Array

)

#

Returns Optional

Returns the last item of the array.

map(

array: ArrayLike,
fn: ( value: A, index: number) => B

)

#

Returns Array

Calls fn function for every member of array and returns a new array out of all outputs.

move(

array: Array,
element: A,
toIndex?: undefined | number

)

#

Returns void

Adds an element to array.

If array already contains and item like this, it is removed before adding it again.

Optionally toIndex can be specified to add element at specific index.

pushAll(

array: Array,
input: Array

)

#

Returns void

Pushes all of the elements from input into array.

pushOne(

array: Array,
element: A

)

#

Returns void

Pushes element into array if it doesn't already exist.

remove(

array: Array,
element: A

)

#

Returns boolean

Removes element from array.

If there are multiple copies of element, they are all removed.

removeFirst(

array: Array,
element: A

)

#

Returns boolean

removeIndex(

array: Array,
index: number

)

#

Returns void

Removes a value from array at specific index.

replace(

array: Array,
element: A,
index?: undefined | number

)

#

Returns void

Removes element from array (if it exists) and then inserts element at index.

If index is not provided, it will insert element at the end of array.

setIndex(

array: Array,
element: A,
index: number

)

#

Returns void

Removes all copies of element from array (if they exist) and then inserts element at index.

shiftLeft(

array: Array,
index: number

)

#

Returns void

Shifts an item at index towards beginning of the array.

shuffle(

array: Array

)

#

Returns void

Iterates through all items in array and calls fn function for each of them.

slice(

array: ArrayLike,
start: number,
end: number

)

#

Returns Array

Returns a copy of array which contains all the elements between start and end. (including start and excluding end)If end is not provided, it defaults to array.length.

toArray(

input: Array | A

)

#

Returns Array

Wraps input in an array, if it isn't already an array.