Returns a new Array or String after inserting and flatten value
at index
.
npm install flat-insert
Returns new modified value depending on input
type.
input
: Input value. (String|Array)value
: Insert value. (Mixed)- If
input
type is String,value
will turn into String. - If
input
andvalue
types are Array, thenvalue
will be flatten.
- If
index
: Index position for insertion. (Number; defaults0
)
var insert = require('flat-insert')
insert([1, 2, 3], [1.1, 1.2], 1)
// → '[1, 1.1, 1.2, 2, 3]'
insert([1, 2, 3], 'meh', 1)
// → '[1, 'meh', 2, 3]'
insert('123', 'yo', 2)
// → '12yo3'
node benchmark.js
insert string into string x 49,334,288 ops/sec ±0.51% (87 runs sampled)
insert 1x array into string x 2,726,256 ops/sec ±0.24% (90 runs sampled)
insert string into 10x array x 1,926,946 ops/sec ±0.69% (84 runs sampled)
insert number into 10x array x 1,904,262 ops/sec ±2.90% (83 runs sampled)
insert object into 10x array x 1,876,367 ops/sec ±3.23% (86 runs sampled)
insert 3x array into 10x array x 1,792,153 ops/sec ±4.13% (81 runs sampled)
See the License file.