Answers for "javascript string into substrings of length"

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 string into substrings of length"

Code answers related to "Javascript"

Browse Popular Code Answers by Language