Observable Array
The ObservableArray module expands the Array class by providng a capability of detecting and responding to changes of a collection of objects.
The ObservableArray supports the known methods like concat, push, reduce, slice, splice, reverse and many more (full list here).
Basics
ObservableArray Module Import
Using the ObservableArray requires the related module.
Creating an ObservableArray
Creating an ObservableArray with different class constructors.
Get, Set and Push Array Item
One difference with the base array implementation is in the way the items are accessed through their index.
While in the common JS array we would do array[index] with an ObservableArray we need to use getItem(index) method.
Setting item at specified index using setItem(index, item) method.
Using push(item) method to add single element to the array.
Using push() method to add multiple elements from source array to the ObservableArray.
Reverse, Shift, and Sort operations
Using reverse() method to reverse the elements order of the ObservableArray.
Using shift() method to remove the first element of the array.
Using sort() method to sort the array. This method can accept a comparing function.
myArray.sort();
Getting Item Index
Using indexOf(item) method to get the index of the desired item in the array.