Splice: Difference between revisions
Jump to navigation
Jump to search
Line 5: | Line 5: | ||
The splice() method adds/removes items to/from an array, and returns the removed item(s). This function changes the original array. | The splice() method adds/removes items to/from an array, and returns the removed item(s). This function changes the original 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. | ''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. | |||
''how many'': The number of items to be removed. If set to 0, no items will be removed. | ''how many'': The number of items to be removed. If set to 0, no items will be removed. |
Revision as of 20:35, 30 December 2013
Splice(array, index, how many[, 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.
how many: 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)
Rem UBound Example 'UBound returns upper bound of array dimension Dim Other, Children(3), Parents(3, 1) Other = Array("Damien", "Pip", "Wendy") Print "'Other' Upper Bound:", Ubound(Other) Print "'Children' Upper Bound:", _ UBound(Children, 1) Print "'Parents' Upper Bounds:", _ UBound(Parents), UBound(Parents, 2)
Example (JavaScript)
// UBound Example /* Length returns upper bound of array dimension + 1 */ var Other, Children=new Array(3), Parents=new Array(3,1); Other= new Array("Damien" , "Pip" , "Wendy"); Parents[3]=''; //need to assign variable to use length on multidim array NSB.Print("'Other' Upper Bounds: " + ((Other.length)-1).toString()); NSB.Print("'Children' Upper Bounds: " + ((Children.length)-1).toString()); NSB.Print("'Parents' Upper Bounds: " + ((Parents.length)-1).toString());
Output
'Other' Upper Bound:2 'Children' Upper Bound: 3 'Parents' Upper Bounds: 3 1