8.8 released—CSS Media Query support, SF Symbols and much more...
Learn more
ObservableArray
Advanced array like class used when you want to be notified when a change occurs.

Summary

Constructors

constructor

new ObservableArray<T>(arrayLength?: number): ObservableArray<T>
Create ObservableArray with specified length.
Parameter Default Description
arrayLength
number

Returns ObservableArray<T>
new ObservableArray<T>(items: T[]): ObservableArray<T>
Create ObservableArray from source Array.
Parameter Default Description
items
T[]

Returns ObservableArray<T>
new ObservableArray<T>(...items: T[]): ObservableArray<T>
Create ObservableArray from T items.
Parameter Default Description
items
T[]

Returns ObservableArray<T>

Properties

changeEvent

Static
changeEvent: string
String value used when hooking to change event.

Accessors

length

get length(): number
Gets or sets the length of the array. This is a number one higher than the highest element defined in an array.
Returns number

Methods

[iterator]

[iterator](): Generator&lt;T, void, unknown&gt;
Returns Generator<T, void, unknown>

_notifyLengthChange

_notifyLengthChange(): void

concat

concat(...args: any[]): ObservableArray<T>
Combines two or more arrays.
Parameter Default Description
args
any[]

Returns ObservableArray<T>

every

every(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean
Determines whether all the members of an array satisfy the specified test.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => boolean

A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.

thisArg
any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns boolean

filter

filter(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): ObservableArray<T>
Returns the elements of an array that meet the condition specified in a callback function.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => boolean

A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.

thisArg
any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns ObservableArray<T>

find

find(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): T
Returns the first element in the array where predicate is true, and null otherwise.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => any

thisArg
any

If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

Returns T

findIndex

findIndex(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): number
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => any

thisArg
any

If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.

Returns number

forEach

forEach(callbackfn: (value: T, index: number, array: ObservableArray<T>) => void, thisArg?: any): void
Performs the specified action for each element in an array.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => void

A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.

thisArg
any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns void

getItem

getItem(pos: number): T
Returns item at specified position. Supports relative indexing from the end of the array when passed a negative index.
Parameter Default Description
pos
number

Returns T

includes

includes(searchElement: T, fromIndex?: number): boolean
Determines whether the specified element exists inside the array.
Parameter Default Description
searchElement
T

The value to locate in the array.

fromIndex
number

The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

Returns boolean

indexOf

indexOf(searchElement: T, fromIndex?: number): number
Returns the index of the first occurrence of a value in an array.
Parameter Default Description
searchElement
T

The value to locate in the array.

fromIndex
number

The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

Returns number

join

join(separator?: string): string
Adds all the elements of an array separated by the specified separator string.
Parameter Default Description
separator
string

A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.

Returns string

lastIndexOf

lastIndexOf(searchElement: T, fromIndex?: number): number
Returns the index of the last occurrence of a specified value in an array.
Parameter Default Description
searchElement
T

The value to locate in the array.

fromIndex
number

The array index at which to begin the search. If fromIndex is omitted, the search starts at the last index in the array.

Returns number

map

map<U>(callbackfn: (value: T, index: number, array: ObservableArray<T>) => U, thisArg?: any): ObservableArray<U>
Calls a defined callback function on each element of an array, and returns an array that contains the results.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => U

A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

thisArg
any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns ObservableArray<U>

pop

pop(): T
Removes the last element from an array and returns it.
Returns T

push

push(...args: T[]): number
Appends new elements to an array, and returns the new length of the array.
Parameter Default Description
args
T[]

Returns number

reduce

reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Parameter Default Description
callbackfn
(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T

A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.

initialValue
T

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

Returns T

reduceRight

reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Parameter Default Description
callbackfn
(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T

A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.

initialValue
T

If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.

Returns T

reverse

reverse(): ObservableArray<T>
Reverses the elements in an Array. This method uses 'in place' algorithm.
Returns ObservableArray<T>

setItem

setItem(pos: number, value: T): void
Sets item at specified position. Supports relative indexing from the end of the array when passed a negative index.
Parameter Default Description
pos
number

value
T

Returns void

shift

shift(): T
Removes the first element from an array and returns it.
Returns T

slice

slice(start?: number, end?: number): ObservableArray<T>
Returns a section of an array.
Parameter Default Description
start
number

The beginning of the specified portion of the array.

end
number

The end of the specified portion of the array.

Returns ObservableArray<T>

some

some(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean
Determines whether the specified callback function returns true for any element of an array.
Parameter Default Description
callbackfn
(value: T, index: number, array: ObservableArray<T>) => boolean

A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.

thisArg
any

An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

Returns boolean

sort

sort(compareFn?: (a: T, b: T) => number): ObservableArray<T>
Sorts an array. This method uses 'in place' algorithm.
Parameter Default Description
compareFn
(a: T, b: T) => number

The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.

Returns ObservableArray<T>

splice

splice(start: number, deleteCount?: number, ...items: T[]): ObservableArray<T>
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. This method uses 'in place' algorithm.
Parameter Default Description
start
number

The zero-based location in the array from which to start removing elements.

deleteCount
number

The number of elements to remove.

items
T[]

Elements to insert into the array in place of the deleted elements.

Returns ObservableArray<T>

toJSON

toJSON(): any[]

toLocaleString

toLocaleString(): string

toString

toString(): string
Returns a string representation of an array.
Returns string

unshift

unshift(...args: T[]): number
Inserts new elements at the start of an array.
Parameter Default Description
args
T[]

Returns number
Previous
Observable
Next
Page