List
Type class
An ordered list of items that dispatches events as items are added, removed or moved.
Sources
List can be used (imported) via one of the following packages.
// Import Listimport * as am5 from "@amcharts/amcharts5";
// Create Listam5.List.new(root, { // ... config if applicable});<!-- Load List --><script src="index.js"></script>
<script>// Create Listam5.List.new(root, { // ... config if applicable});</script>Inheritance
List does not extend any other symbol.
List is extended by Children, ListAutoDispose, ListData.
Properties
eventsType
EventDispatcherDefaultnew EventDispatcher()lengthType
numberNumber of items in list.
valuesType
ArrayAn array of values in the list.
Don't change this array directly: use methods like
push()andremoveIndex(), which dispatch the list's events.
Methods
[Symbol.iterator]()Returns
IteratorReturns an ES6 iterator for the list.
clear()Returns
voidRemoves all items from the list.
constructor(initial:Array)Returns
ListConstructor
contains(value:T)Returns
booleanChecks if list contains specific item reference.
copyFrom(source:this)Returns
voidAdds all items of another list to the end of this one.
each(f: (value:T, index:number) =>void)Returns
voidCalls
ffor each item in the list, with the item and its index.eachReverse(f: (value:T, index:number) =>void)Returns
voidCalls
ffor each item in the list, from last to first, with the item and its index.getIndex(index:number)Returns
T|undefinedReturns an item at specified index.
hasIndex(index:number)Returns
booleanChecks if there's a value at specific index.
indexOf(value:T)Returns
numberSearches the list for specific item and returns its index.
insertIndex(index:number,
value:K)Returns
KInserts an item at
index, moving the items from there on one place further.moveValue(value:K,
toIndex?:undefined|number)Returns
KMoves an item to
toIndex, or to the end of the list iftoIndexis not set. An item that is not in the list yet is added.pop()Returns
OptionalReturns the last item from the list, and removes it.
push(value:K)Returns
KAdds an item to the end of the list.
pushAll(values:Array)Returns
voidAdds multiple items to the end of the list.
removeIndex(index:number)Returns
TRemoves a value at specific index.
removeValue(value:T)Returns
voidRemoves all copies of an item from the list.
setAll(newArray:Array)Returns
voidReplaces all items in the list with
newArray.setIndex(index:number,
value:T)Returns
TReplaces the value at
index, which must already exist.shift()Returns
OptionalReturns the first item from the list, and removes it.
swap(a:number,
b:number)Returns
voidSwaps two items in the list.
unshift(value:K)Returns
KAdds an item as a first item in the list.
Events
Add event handlers to List object using its events.on() method. Read about adding event handlers.
clearParam { type:
"clear", target:List, oldValues:Array}All items were removed, by
clear()orsetAll().insertIndexParam { type:
"insertIndex", target:List, index:number, newValue:A}An item was inserted at
index.moveIndexParam { type:
"moveIndex", target:List, newIndex:number, oldIndex:number, value:A}An item was moved from
oldIndextonewIndex.pushParam { type:
"push", target:List, newValue:A}An item was added to the end of the list.
removeIndexParam { type:
"removeIndex", target:List, index:number, oldValue:A}The item at
indexwas removed.setIndexParam { type:
"setIndex", target:List, index:number, newValue:A, oldValue:A}The item at
indexwas replaced.swapParam { type:
"swap", target:List, a:A, b:A}Two items swapped places.