You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chunki exposes two methods; one for splitting array into chunks based on size and another for combining them together.
chunki has two utility functions:
One to split an array into smaller chunks.
Another to combine chunks into a single array.
Chunk Method
const{ chunk }=require("chunki");// If you are using es6 import feature//import { chunk } = from "chunki";constarr=[1,2,3,4,5,6];constchunks=chunk(arr,2);// 2 --> chunk sizeconsole.log(chunks);// [ [ 1, 2 ], [ 3, 4 ], [ 5, 6 ] ]//Splitting objects into chunksconstarr=[{name: "john"},{name: "Patlu"}];constchunks=chunk(arr,1);console.log(chunks);//[ [ { name: 'john' } ], [ { name: 'Patlu' } ] ]
Flatten Method
const{ flatten }=require("chunki");// If you are using es6 import feature//import { flatten } = from "chunki";constchunks=[[1,2],[3,4],[5,6],];constflattenArr=flatten(chunks);console.log(flattenArr);//[ 1, 2, 3, 4, 5, 6 ]
About
A npm package for making chunks from an array and combined the chunks