Add item to array in VBScript

arraysvbscript

How do you add an item to an existing array in VBScript?

Is there a VBScript equivalent to the push function in Javascript?

i.e.

myArray has three items, "Apples", "Oranges", and "Bananas" and I want to add "Watermelons" to the end of the array.

Best Answer

Arrays are not very dynamic in VBScript. You'll have to use the ReDim Preserve statement to grow the existing array so it can accommodate an extra item:

ReDim Preserve yourArray(UBound(yourArray) + 1)
yourArray(UBound(yourArray)) = "Watermelons"