Answers for "javascript break string into chunks"

2

javascript string into substrings of length

function chunkSubstr(str, size) {
  const numChunks = Math.ceil(str.length / size)
  const chunks = new Array(numChunks)

  for (let i = 0, o = 0; i < numChunks; ++i, o += size) {
    chunks[i] = str.substr(o, size)
  }

  return chunks
}
Posted by: Guest on March-05-2020
0

how to split a string into chunks nodejs

function chunkString(str, length) {
  return str.match(new RegExp('.{1,' + length + '}', 'g'));
}
Posted by: Guest on October-30-2020

Code answers related to "javascript break string into chunks"

Code answers related to "Javascript"

Browse Popular Code Answers by Language