1.0.6 • Published 5 years ago

array-interval-insert v1.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

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"]
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago