Answers for "javascript how to split a string into chunks of equal size"

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

Code answers related to "javascript how to split a string into chunks of equal size"

Code answers related to "Javascript"

Browse Popular Code Answers by Language