Splice: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Line 15: Line 15:
== Example (Basic) ==
== Example (Basic) ==


At position 2, remove 2 items:
<pre>
<pre>
Rem UBound Example
fruits = ["Banana", "Orange", "Apple", "Mango"]
'UBound returns upper bound of array dimension
Splice(fruits,2,2)
 
</pre>
Dim Other, Children(3), Parents(3, 1)
The result of fruits will be:
Other = Array("Damien", "Pip", "Wendy")
<pre>
Print "'Other' Upper Bound:", Ubound(Other)
Banana,Orange
Print "'Children' Upper Bound:", _
      UBound(Children, 1)
Print "'Parents' Upper Bounds:", _
      UBound(Parents), UBound(Parents, 2)
</pre>
</pre>



Revision as of 20:38, 30 December 2013

Splice(array, index, howmany[, item])

Description

The splice() method adds/removes items to/from an array, and returns the removed item(s). This function changes the original array.

array: The name of an existing array.

index: An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array.

howmany: The number of items to be removed. If set to 0, no items will be removed.

item: Optional. The new item(s) to be added to the array at index.

Example (Basic)

At position 2, remove 2 items:

fruits = ["Banana", "Orange", "Apple", "Mango"]
Splice(fruits,2,2)

The result of fruits will be:

Banana,Orange

Example (JavaScript)

At position 2, remove 2 items:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2,2);

The result of fruits will be:

Banana,Orange

Output

'Other' Upper Bound:2
'Children' Upper Bound:    3
'Parents' Upper Bounds:    3      1

Related Items

Array, Dim, LBound, ReDim