Files
NativeScript/apps/tests/observable-array.md
2016-04-14 15:20:35 +03:00

113 lines
4.5 KiB
Markdown

---
nav-title: "observable-array How-To"
title: "How-To"
description: "Examples for using observable-array"
---
# Observable Array module
<snippet id='observable-array-require'/>
### Create ObservableArray from array.
<snippet id='observable-array-create'/>
### Create ObservableArray from arguments.
<snippet id='observable-array-arguments'/>
### Create ObservableArray with specific length.
<snippet id='observable-array-length'/>
### Set ObservableArray length to new value.
<snippet id='observable-array-newvalue'/>
### Get item at specified index using getItem(index) method.
<snippet id='observable-array-getitem'/>
### Set item at specified index using setItem(index, item) method.
<snippet id='observable-array-setitem'/>
### Set item at specified index using setItem(index, item) method and observe change event data.
<snippet id='observable-array-eventdata'/>
### Use concat() method to combine ObservableArray with array.
<snippet id='observable-array-combine'/>
### Use join() method to convert ObservableArray to comma separated string.
<snippet id='observable-array-join'/>
### Use join(separator) method to convert ObservableArray to string separated with specified separator.
<snippet id='observable-array-join-separator'/>
### Use pop() method to remove the last element.
<snippet id='observable-array-join-pop'/>
### Handle "change" event to know more info about the change after calling pop() method.
<snippet id='observable-array-join-change'/>
### Use push() method to add single element to the array.
<snippet id='observable-array-push'/>
### Handle "change" event to know more info about the change after calling push() method with single element.
<snippet id='observable-array-change-push'/>
### Use push() method to add multiple elements to the array.
<snippet id='observable-array-push-multiple'/>
### Handle "change" event to know more info about the change after calling push() method with multiple elements.
<snippet id='observable-array-push-multiple-info'/>
### Use push() method to add multiple elements from source array to the ObservableArray.
<snippet id='observable-array-push-source'/>
### Handle "change" event to know more info about the change after calling push() method with multiple elements from source array.
<snippet id='observable-array-push-source-info'/>
### Use reverse() method to reverse the elements order of the ObservableArray.
<snippet id='observable-array-reverse'/>
### Use shift() method to remove the first element of the array.
<snippet id='observable-array-shift'/>
### Handle "change" event to know more info about the change after calling shift() method.
<snippet id='observable-array-shift-change'/>
### Use slice() method to return array with all ObservableArray elements.
<snippet id='observable-array-slice'/>
### Use slice(star, end) method to return section of the array.
<snippet id='observable-array-slice-args'/>
### Use sort() method to sort the array.
<snippet id='observable-array-sort'/>
### Use sort(compareFunction) method to sort the array with your own comparing logic.
<snippet id='observable-array-sort-comparer'/>
### Use splice(start, deleteCount) method to delete elements in the array.
<snippet id='observable-array-splice'/>
### Handle "change" event to know more info about the change after calling splice(start, deleteCount) method.
<snippet id='observable-array-splice-change'/>
### Use splice(start, deleteCount, ...arguments) method to remove and insert elements in the array.
<snippet id='observable-array-splice-args'/>
### Handle "change" event to know more info about the change after calling splice(start, deleteCount, ...arguments) method.
<snippet id='observable-array-splice-args-change'/>
### Use unshift(item1, item2... itemN) method to insert elements from the start of the array.
<snippet id='observable-array-unshift'/>
### Handle "change" event to know more info about the change after calling unshift(item1, item2... itemN) method.
<snippet id='observable-array-unshift-change'/>
### Use indexOf(item) method to get the index of the desired item in the array.
<snippet id='observable-array-indexof'/>
### Use indexOf(item, fromIndex) method to get the index of the desired item in the array starting from specified index.
<snippet id='observable-array-indexof-args'/>
### Use lastIndexOf(item) method to get the last index of the desired item in the array.
<snippet id='observable-array-lastindexof'/>
### Use lastIndexOf(item, fromIndex) method to get the last index of the desired item in the array starting from specified index.
<snippet id='observable-array-lastindexof-args'/>