Skip to content

Commit fe7a2ed

Browse files
committed
Add documentation for _.insert (documentcloud#199)
1 parent 12fd389 commit fe7a2ed

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/underscore.array.builders.js.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,20 @@ _.cycle(5, [1,2,3]);
152152

153153
--------------------------------------------------------------------------------
154154

155+
#### insert
156+
157+
Given an array, an index and a value, insert the value at this index in the array. The value that was previously at this index shifts one position up, together with any values that may come after it. `_.insert` modifies the array in place and also returns it. Useful shorthand for `Array.prototype.splice.call(array, index, 0, value)`.
158+
159+
```javascript
160+
var array = [1, 2, 3];
161+
var result = _.insert(array, 1, 4);
162+
//=> [1, 4, 2, 3]
163+
result === array;
164+
//=> true
165+
```
166+
167+
--------------------------------------------------------------------------------
168+
155169
#### interpose
156170

157171
The `_.interpose` function takes an array and an element and returns a new array with the given element inserted betwixt every element in the original array:

0 commit comments

Comments
 (0)