Try the below code:
var foo = "foofaafoofaafoofaafoofaafoofaa";
console.log( foo.match(/.{1,3}/g) );
For nth position:
foo.match(new RegExp('.{1,' + n + '}', 'g'));
More Related Contents:
- How to replace all occurrences of a string in JavaScript
- How can I do string interpolation in JavaScript?
- Generate random string/characters in JavaScript
- How do you reverse a string in-place in JavaScript?
- Efficiently replace all accented characters in a string?
- How to remove all line breaks from a string
- Why is [1,2] + [3,4] = “1,23,4” in JavaScript?
- Why is string “11” less than string “3”? [duplicate]
- Convert camelCaseText to Title Case Text
- How to create a date object from string in javascript [duplicate]
- How do I replace all occurrences of a string in JavaScript?
- How to check if character is a letter in Javascript?
- Using JavaScript to perform text matches with/without accented characters
- How can val() return Number?
- How does adding String with Integer work in JavaScript? [duplicate]
- detect differences between two strings with Javascript
- Remove empty strings from array while keeping record Without Loop?
- How do I split a string by whitespace and ignoring leading and trailing whitespace into an array of words using a regular expression?
- Replace string in javascript array
- Cutting a string at nth occurrence of a character
- JavaScript – Replace all commas in a string [duplicate]
- Replacing accented characters with plain ascii ones [duplicate]
- Create a string of variable length, filled with a repeated character
- Convert JavaScript String to be all lowercase
- String split returns an array with more elements than expected (empty elements)
- How can I get a character array from a string?
- Best way to parse HTML in Javascript
- Put quotes around a variable string in JavaScript
- how to split a string in javascript [duplicate]
- Wildcard string comparison in Javascript