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


insert($index, $item) -> self


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