Adds the given item, or array of items, to the array starting at the index specified.
Each item must be unique within the array.
Existing elements in the array are shifted up.
The array is modified in-place and returned.
You can optionally specify a limit to the maximum size of the array. If the quantity of items being added will take the array length over this limit, it will stop adding once the limit is reached.
You can optionally specify a callback to be invoked for each item successfully added to the array.
name | type | arguments | description |
---|---|---|---|
array | array |
The array to be added to. |
|
item | any | Array.<any> |
The item, or array of items, to add to the array. |
|
index | number | <optional> |
The index in the array where the item will be inserted. |
limit | number | <optional> |
Optional limit which caps the size of the array. |
callback | function | <optional> |
A callback to be invoked for each item successfully added to the array. |
context | object | <optional> |
The context in which the callback is invoked. |
The input array.