NativeScript 9.1 Released → V8 14.9, Vite 8 HMR, built for rapid agentic visual iteration
Dig in

Defined in: data/observable-array/index.ts

Advanced array like class used when you want to be notified when a change occurs.

Extends ​

Type Parameters ​

Type Parameter
T

Constructors ​

Constructor ​

ts
new ObservableArray<T>(arrayLength?: number): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Create ObservableArray<T> with specified length.

Parameters ​

ParameterType
arrayLength?number

Returns ​

ObservableArray<T>

Overrides ​

Observable.constructor

Constructor ​

ts
new ObservableArray<T>(items: T[]): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Create ObservableArray<T> from source Array<T>.

Parameters ​

ParameterType
itemsT[]

Returns ​

ObservableArray<T>

Overrides ​

ts
Observable.constructor

Constructor ​

ts
new ObservableArray<T>(...items: T[]): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Create ObservableArray<T> from T items.

Parameters ​

ParameterType
...itemsT[]

Returns ​

ObservableArray<T>

Overrides ​

ts
Observable.constructor

Properties ​

changeEvent ​

ts
static changeEvent: string;

Defined in: data/observable-array/index.ts

String value used when hooking to change event.


propertyChangeEvent ​

ts
static propertyChangeEvent: string;

Defined in: data/observable/index.ts

String value used when hooking to propertyChange event.

Ns Event ​

propertyChange

Inherited from ​

Observable.propertyChangeEvent

Accessors ​

length ​

Get Signature ​

ts
get length(): number;

Defined in: data/observable-array/index.ts

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

Returns ​

number

Set Signature ​

ts
set length(value: number): void;

Defined in: data/observable-array/index.ts

Parameters ​
ParameterType
valuenumber
Returns ​

void

Methods ​

_createPropertyChangeData() ​

ts
_createPropertyChangeData(
   propertyName: string, 
   value: any, 
   oldValue?: any): PropertyChangeData;

Defined in: data/observable/index.ts

This method is intended to be overriden by inheritors to provide additional implementation.

Parameters ​

ParameterType
propertyNamestring
valueany
oldValue?any

Returns ​

PropertyChangeData

Inherited from ​

Observable._createPropertyChangeData


_emit() ​

ts
_emit(eventName: string): void;

Defined in: data/observable/index.ts

Parameters ​

ParameterType
eventNamestring

Returns ​

void

Inherited from ​

Observable._emit


_notifyLengthChange() ​

ts
_notifyLengthChange(): void;

Defined in: data/observable-array/index.ts

Returns ​

void


[iterator]() ​

ts
iterator: Generator<T, void, unknown>;

Defined in: data/observable-array/index.ts

Returns ​

Generator<T, void, unknown>


addEventListener() ​

ts
addEventListener(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any, 
   once?: boolean): void;

Defined in: data/observable/index.ts

Adds a listener for the specified event name.

Parameters ​

ParameterTypeDescription
eventNamestringName of the event to attach to.
callback(data: EventData) => voidA function to be called when some of the specified event(s) is raised.
thisArg?anyAn optional parameter which when set will be used as "this" in callback method call.
once?booleanAn optional parameter which when set will cause the event listener to fire once.

Returns ​

void

Inherited from ​

Observable.addEventListener


concat() ​

ts
concat(...args: any[]): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Combines two or more arrays.

Parameters ​

ParameterType
...argsany[]

Returns ​

ObservableArray<T>


every() ​

ts
every(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean;

Defined in: data/observable-array/index.ts

Determines whether all the members of an array satisfy the specified test.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => booleanA 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?anyAn 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() ​

ts
filter(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Returns the elements of an array that meet the condition specified in a callback function.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => booleanA function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
thisArg?anyAn 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() ​

ts
find(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): T;

Defined in: data/observable-array/index.ts

Returns the first element in the array where predicate is true, and null otherwise.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => any-
thisArg?anyIf 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() ​

ts
findIndex(callbackfn: (value: T, index: number, array: ObservableArray<T>) => any, thisArg?: any): number;

Defined in: data/observable-array/index.ts

Returns the index of the first element in the array where predicate is true, and -1 otherwise.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => any-
thisArg?anyIf 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() ​

ts
forEach(callbackfn: (value: T, index: number, array: ObservableArray<T>) => void, thisArg?: any): void;

Defined in: data/observable-array/index.ts

Performs the specified action for each element in an array.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => voidA function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
thisArg?anyAn 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


get() ​

ts
get(name: string): any;

Defined in: data/observable/index.ts

Gets the value of the specified property.

Parameters ​

ParameterType
namestring

Returns ​

any

Inherited from ​

Observable.get


getItem() ​

ts
getItem(pos: number): T;

Defined in: data/observable-array/index.ts

Returns item at specified position. Supports relative indexing from the end of the array when passed a negative index.

Parameters ​

ParameterType
posnumber

Returns ​

T


hasListeners() ​

ts
hasListeners(eventName: string): boolean;

Defined in: data/observable/index.ts

Checks whether a listener is registered for the specified event name.

Parameters ​

ParameterTypeDescription
eventNamestringThe name of the event to check for.

Returns ​

boolean

Inherited from ​

Observable.hasListeners


includes() ​

ts
includes(searchElement: T, fromIndex?: number): boolean;

Defined in: data/observable-array/index.ts

Determines whether the specified element exists inside the array.

Parameters ​

ParameterTypeDescription
searchElementTThe value to locate in the array.
fromIndex?numberThe array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

Returns ​

boolean


indexOf() ​

ts
indexOf(searchElement: T, fromIndex?: number): number;

Defined in: data/observable-array/index.ts

Returns the index of the first occurrence of a value in an array.

Parameters ​

ParameterTypeDescription
searchElementTThe value to locate in the array.
fromIndex?numberThe array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.

Returns ​

number


join() ​

ts
join(separator?: string): string;

Defined in: data/observable-array/index.ts

Adds all the elements of an array separated by the specified separator string.

Parameters ​

ParameterTypeDescription
separator?stringA 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() ​

ts
lastIndexOf(searchElement: T, fromIndex?: number): number;

Defined in: data/observable-array/index.ts

Returns the index of the last occurrence of a specified value in an array.

Parameters ​

ParameterTypeDescription
searchElementTThe value to locate in the array.
fromIndex?numberThe 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() ​

ts
map<U>(callbackfn: (value: T, index: number, array: ObservableArray<T>) => U, thisArg?: any): ObservableArray<U>;

Defined in: data/observable-array/index.ts

Calls a defined callback function on each element of an array, and returns an array that contains the results.

Type Parameters ​

Type Parameter
U

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => UA function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
thisArg?anyAn 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>


notify() ​

ts
notify<T>(data: T): void;

Defined in: data/observable/index.ts

Notify this Observable instance with some data. This causes all event handlers on the Observable instance to be called, as well as any 'global' event handlers set on the instance's class.

Type Parameters ​

Type Parameter
T extends Optional<EventData, "object">

Parameters ​

ParameterTypeDescription
dataTan object that satisfies the EventData interface, though with an optional 'object' property. If left undefined, the 'object' property will implicitly be set as this Observable instance.

Returns ​

void

Inherited from ​

Observable.notify


notifyPropertyChange() ​

ts
notifyPropertyChange(
   name: string, 
   value: any, 
   oldValue?: any): void;

Defined in: data/observable/index.ts

Notifies all the registered listeners for the property change event.

Parameters ​

ParameterType
namestring
valueany
oldValue?any

Returns ​

void

Inherited from ​

Observable.notifyPropertyChange


off() ​

ts
off(
   eventName: string, 
   callback?: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Removes the listener(s) for the specified event name.

Parameters ​

ParameterTypeDescription
eventNamestringThe name of the event.
callback?(data: EventData) => voidAn optional specific event listener to remove (if omitted, all event listeners by this name will be removed).
thisArg?anyAn optional parameter which, when set, will be used to refine search of the correct event listener to be removed.

Returns ​

void

Inherited from ​

Observable.off


on() ​

Call Signature ​

ts
on(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable-array/index.ts

Adds a listener for the specified event name.

Parameters ​
ParameterTypeDescription
eventNamestringThe name of the event.
callback(data: EventData) => voidThe event listener to add. Will be called when an event of the given name is raised.
thisArg?anyAn optional parameter which, when set, will be bound as the this context when the callback is called. Falsy values will be not be bound.
Returns ​

void

Inherited from ​

Observable.on

Call Signature ​

ts
on(
   event: "change", 
   callback: (args: ChangedData<T>) => void, 
   thisArg?: any): void;

Defined in: data/observable-array/index.ts

Parameters ​
ParameterType
event"change"
callback(args: ChangedData<T>) => void
thisArg?any
Returns ​

void

Inherited from ​
ts
Observable.on

once() ​

ts
once(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Adds a listener for the specified event name, which, once fired, will remove itself.

Parameters ​

ParameterTypeDescription
eventNamestringThe name of the event.
callback(data: EventData) => voidThe event listener to add. Will be called when an event of the given name is raised.
thisArg?anyAn optional parameter which, when set, will be bound as the this context when the callback is called. Falsy values will be not be bound.

Returns ​

void

Inherited from ​

Observable.once


pop() ​

ts
pop(): T;

Defined in: data/observable-array/index.ts

Removes the last element from an array and returns it.

Returns ​

T


push() ​

ts
push(...args: T[]): number;

Defined in: data/observable-array/index.ts

Appends new elements to an array, and returns the new length of the array.

Parameters ​

ParameterType
...argsT[]

Returns ​

number


reduce() ​

ts
reduce(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T;

Defined in: data/observable-array/index.ts

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.

Parameters ​

ParameterTypeDescription
callbackfn(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => TA function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
initialValue?TIf 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() ​

ts
reduceRight(callbackfn: (previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => T, initialValue?: T): T;

Defined in: data/observable-array/index.ts

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.

Parameters ​

ParameterTypeDescription
callbackfn(previousValue: T, currentValue: T, currentIndex: number, array: ObservableArray<T>) => TA function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
initialValue?TIf 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


removeEventListener() ​

ts
removeEventListener(
   eventName: string, 
   callback?: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Removes listener(s) for the specified event name.

Parameters ​

ParameterTypeDescription
eventNamestringName of the event to attach to.
callback?(data: EventData) => voidAn optional parameter pointing to a specific listener. If not defined, all listeners for the event names will be removed.
thisArg?anyAn optional parameter which when set will be used to refine search of the correct callback which will be removed as event listener.

Returns ​

void

Inherited from ​

Observable.removeEventListener


reverse() ​

ts
reverse(): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Reverses the elements in an Array. This method uses 'in place' algorithm.

Returns ​

ObservableArray<T>


set() ​

ts
set(name: string, value: any): void;

Defined in: data/observable/index.ts

Updates the specified property with the provided value.

Parameters ​

ParameterType
namestring
valueany

Returns ​

void

Inherited from ​

Observable.set


setItem() ​

ts
setItem(pos: number, value: T): void;

Defined in: data/observable-array/index.ts

Sets item at specified position. Supports relative indexing from the end of the array when passed a negative index.

Parameters ​

ParameterType
posnumber
valueT

Returns ​

void


setProperty() ​

ts
setProperty(name: string, value: any): void;

Defined in: data/observable/index.ts

Updates the specified property with the provided value and raises a property change event and a specific change event based on the property name.

Parameters ​

ParameterType
namestring
valueany

Returns ​

void

Inherited from ​

Observable.setProperty


shift() ​

ts
shift(): T;

Defined in: data/observable-array/index.ts

Removes the first element from an array and returns it.

Returns ​

T


slice() ​

ts
slice(start?: number, end?: number): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Returns a section of an array.

Parameters ​

ParameterTypeDescription
start?numberThe beginning of the specified portion of the array.
end?numberThe end of the specified portion of the array.

Returns ​

ObservableArray<T>


some() ​

ts
some(callbackfn: (value: T, index: number, array: ObservableArray<T>) => boolean, thisArg?: any): boolean;

Defined in: data/observable-array/index.ts

Determines whether the specified callback function returns true for any element of an array.

Parameters ​

ParameterTypeDescription
callbackfn(value: T, index: number, array: ObservableArray<T>) => booleanA 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?anyAn 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() ​

ts
sort(compareFn?: (a: T, b: T) => number): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Sorts an array. This method uses 'in place' algorithm.

Parameters ​

ParameterTypeDescription
compareFn?(a: T, b: T) => numberThe 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() ​

ts
splice(
   start: number, 
   deleteCount?: number, ...
items: T[]): ObservableArray<T>;

Defined in: data/observable-array/index.ts

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. This method uses 'in place' algorithm.

Parameters ​

ParameterTypeDescription
startnumberThe zero-based location in the array from which to start removing elements.
deleteCount?numberThe number of elements to remove.
...items?T[]Elements to insert into the array in place of the deleted elements.

Returns ​

ObservableArray<T>


toJSON() ​

ts
toJSON(): any[];

Defined in: data/observable-array/index.ts

Returns ​

any[]


toLocaleString() ​

ts
toLocaleString(): string;

Defined in: data/observable-array/index.ts

Returns a date converted to a string using the current locale.

Returns ​

string


toString() ​

ts
toString(): string;

Defined in: data/observable-array/index.ts

Returns a string representation of an array.

Returns ​

string


unshift() ​

ts
unshift(...args: T[]): number;

Defined in: data/observable-array/index.ts

Inserts new elements at the start of an array.

Parameters ​

ParameterType
...argsT[]

Returns ​

number


addEventListener() ​

ts
static addEventListener(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any, 
   once?: boolean): void;

Defined in: data/observable/index.ts

Please avoid using the static event-handling APIs as they will be removed in future.

Parameters ​

ParameterType
eventNamestring
callback(data: EventData) => void
thisArg?any
once?boolean

Returns ​

void

Deprecated ​

Inherited from ​

Observable.addEventListener


off() ​

ts
static off(
   eventName: string, 
   callback?: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Please avoid using the static event-handling APIs as they will be removed in future.

Parameters ​

ParameterType
eventNamestring
callback?(data: EventData) => void
thisArg?any

Returns ​

void

Deprecated ​

Inherited from ​

Observable.off


on() ​

ts
static on(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any, 
   once?: boolean): void;

Defined in: data/observable/index.ts

Please avoid using the static event-handling APIs as they will be removed in future.

Parameters ​

ParameterType
eventNamestring
callback(data: EventData) => void
thisArg?any
once?boolean

Returns ​

void

Deprecated ​

Inherited from ​

Observable.on


once() ​

ts
static once(
   eventName: string, 
   callback: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Please avoid using the static event-handling APIs as they will be removed in future.

Parameters ​

ParameterType
eventNamestring
callback(data: EventData) => void
thisArg?any

Returns ​

void

Deprecated ​

Inherited from ​

Observable.once


removeEventListener() ​

ts
static removeEventListener(
   eventName: string, 
   callback?: (data: EventData) => void, 
   thisArg?: any): void;

Defined in: data/observable/index.ts

Please avoid using the static event-handling APIs as they will be removed in future.

Parameters ​

ParameterType
eventNamestring
callback?(data: EventData) => void
thisArg?any

Returns ​

void

Deprecated ​

Inherited from ​

Observable.removeEventListener

Previous
Observable
Next
Page