Version: v0.8.1 - Beta.  We welcome contributors & feedback.

List.insert

insert($index, $item) -> self

Description

Add an item to the List at $index.

This will bump all items to the right that are currently at that index or higher (adding 1 to their index.)

If $index is negative, it counts from the end of the list (the last item is at -1).

This function is the opposite of remove.

To add an item to the end of the List, use push.

['a', 'b'].insert(1, 'X')
//= ['X', 'a', 'b']

['a', 'b'].insert(-1, 'X')
//= ['a', 'X', 'b']

See Also