Allows us to break text into chunks of specified size. - Node.js String

Node.js examples for String:Split

Description

Allows us to break text into chunks of specified size.

Demo Code


String.prototype.chunk = function(n)
{
  if (typeof n=='undefined')
  {/*from  w  w w . j  a  va 2 s  .  co m*/
    n=2;
  }
  return this.match(RegExp('.{1,'+n+'}','g'));
};

Related Tutorials