Insert Item into List

Verb: insert

Inserts an item into a List at a specified position.

Collections are enumerable data structures that can be accessed using indexes and keys.

Syntax

insert --index(Numeric) --value(Variant) --collection(List<Variant>)

Inputs

Script Designer Required AcceptedTypes Description
--index Index Required Number Position where the item is inserted at.
--value Item to Insert Required Any Item that should be inserted into the collection.
--collection Collection Required List<Any> Collection in which the item is inserted.

Example

Inserts the item "G" at the seventh position of the list.

defVar --name lettersCollection --type List --innertype String --value "[A,B,C,D,E,F,H,I,J,K,L,M]"
insert --index 7 --value G --collection "${lettersCollection}"
logMessage --message "${lettersCollection}" --type "Info"
//The result obtained in "${lettersCollection}" after the operation is: [A,B,C,D,E,F,G,H,I,J,K,L,M]

Remarks

In the Item to Insert parameter, the item to be inserted must be of the same type as the List's.

See Also

  • Copy List with Restrictions
  • Get Item Index
  • Remove From List
  • Remove Value