README
Why this package?
If you want to make an interval insertion into an existing array, you may need this simple package to make things easy.
Installation:
NPM
npm i array-interval-insert
Basic usage:
let intervalInsert = require('array-interval-insert')
let students = [{name: 'Alex'}, {name: 'Bob'}, {name:'Alfredo'}]
let yy = intervalInsert(students, '11')
console.log(yy)
// result:
// (5) [{…}, "11", {…}, "11", {…}]
Syntax
intervalInsert(array, insertion, beforeStart=false, afterLast=false)
array: any[]
An array to copy and make insertion.insertion: string | number | {}
String, number or object you want to insert into the first argument.beforeStart:boolean
If truthy, insertion will be also added as the first item of target array.
Default to false.afterLast:boolean
If truthy, insertion will be also added as the last item of target array.
Default to false.
Examples:
let intervalInsert = require('array-interval-insert')
yy = intervalInsert(students, '11', 1)
console.log(yy)
// result:
// (6) ["11", {…}, "11", {…}, "11", {…}]
zz = intervalInsert(students, '11', 1, 1)
console.log(zz)
//result:
// (7) ["11", {…}, "11", {…}, "11", {…}, "11"]