RemoveFromArray

See Also: Array Functions, InsertInArray, Array Variable Assignments, Working with Arrays

Purpose

Returns a contracted copy of the specified array where the element at the specified index is removed.

Return Type

Array

Syntax

RemoveFromArray( {ArrayId}, {index} )

Where:

What it Does

Returns a contracted copy of the specified array where the element at the specified index is removed. The returned array is a contracted copy of {ArrayId} where the element at the specified {index} is removed, such that the corresponding index of all remaining elements from {index} in the source {ArrayId} is shifted -1.

RemoveFromArray cannot be used with static arrays.

Use AppendArray to append one or more elements from on array to another array.

Use InsertInArray to insert or append individual array elements to an array.

Examples

This sample code will return an array with the values 1,3,4.

Integer[] myArray

 

Move 1 to myArray[0]

Move 2 to myArray[1]

Move 3 to myArray[2]

Move 4 to myArray[3]

 

Move (RemoveFromArray(myArray, 1)) to myArray

This sample code will return an array with the values 1,2,3. Since -1 is passed as the index, the last item is removed from the array.

Integer[] myArray

 

Move 1 to myArray[0]

Move 2 to myArray[1]

Move 3 to myArray[2]

Move 4 to myArray[3]

 

Move (RemoveFromArray(myArray, -1)) to myArray

This sample code will return an array of 2 tFriend structs where friend Frank Jones was removed as the second array element (at index 1).

Struct tFriend

    String First

    String Last

End_Struct

 

tFriend[] myFriends

 

Move "Joe" to myFriends[0].First

Move "Cool" to myFriends[0].Last

Move "Frank" to myFriends[1].First

Move "Jones" to myFriends[1].Last

Move "Susie" to myFriends[2].First

Move "Smith" to myFriends[2].Last

 

Move (RemoveFromArray(myFriends, 1)) to myFriends

 

RemoveFromArray cannot be used with static arrays, since elements cannot be removed from a static array. Instead, you can move blank or zero values to a static array element to "remove" an element.

Integer[4] myArray

 

Move 1 to myArray[0]

Move 2 to myArray[1]

Move 3 to myArray[2]

Move 4 to myArray[3]

 

// "remove" the element in array index 2

Move 0 to myArray[2]