Try this

function splitValue(value, index) {
    return value.substring(0, index) + "," + value.substring(index);
}

console.log(splitValue("3123124", 2));

Answer from Chamika Sandamal on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › split
String.prototype.split() - JavaScript | MDN
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
Discussions

Split string into individual characters?
Split string into individual characters · You have passed it a string with a space in it - that is you telling it to break it up using the spaces as delimiters. If you send it nothing, it will just break it into every character, split(); · The split() method divides a String into an ordered ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
July 23, 2021
Split String at Index?
I’m basically wondering if I could do something like this: string.split(string,index) This doesn’t work but it doesn’t error, it just doesn’t split anything. Does anyone know something like this that would work? Or do … More on devforum.roblox.com
🌐 devforum.roblox.com
1
0
September 3, 2022
Efficient way to split string at specific index
I’m currently trying to parse a file whose data lines are composed of 8 character columns without delimiter. Such as 11111111222222223333333344444444555555556666666677777777888888889999999911111111 So far, I’m working with indices and comprehension to do that with split8_1(str::String) ... More on discourse.julialang.org
🌐 discourse.julialang.org
1
0
April 28, 2022
How to predict what index part of a string will split too based only on an index in the larger string?

I don't really understand what you're asking or what problem you're trying to solve?

Have you considered something like a rope data structure? I've heard that's used in text editors.

More on reddit.com
🌐 r/learnjavascript
6
5
December 19, 2021
🌐
W3Schools
w3schools.com › jsref › jsref_split.asp
JavaScript String split() Method
The split() method splits a string into an array of substrings.
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-index-split-and-manipulate-strings-in-javascript
How To Index, Split, and Manipulate Strings in JavaScript | DigitalOcean
August 24, 2021 - Now that we have a new array in ... with an index number. ... If an empty parameter is given, split() will create a comma-separated array with each character in the string. By splitting strings you can determine how many words are in a sentence, and use the method as a way to determine people’s first names and last names, for example. The JavaScript trim() method ...
🌐
SitePoint
sitepoint.com › blog › javascript › quick tip: how to split a string into substrings in javascript
How to Split a String into Substrings in JavaScript — SitePoint
November 6, 2024 - In this example, you retrieve the index of the hash character # in the variable url. If the value of the index is not -1, you retrieve the substring from url starting at the index of the hash. You can try it out in the following CodePen demo. See the Pen Using substring with indexOf to split string by SitePoint (@SitePoint) on CodePen.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Split string into individual characters? - JavaScript - The freeCodeCamp Forum
July 23, 2021 - This code var chars = "the".split(" "); console.log(chars); seems to put the entire word “the” into index 0 of an array. But I want it to print out like [‘t’, ‘h’, ‘e’]
🌐
Medium
medium.com › nerd-for-tech › basics-of-javascript-string-split-method-4647aa1b0f4e
Basics of Javascript · String · split() (method) | by Jakub Korch | Nerd For Tech | Medium
June 20, 2021 - You can see that happening in case of separator being regular expression, where we are searching for capital letter optionally preceded by empty space. Capital H at the beginning of the string fits this condition, so the split creates empty space as a first element of the resulting array.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › slice
String.prototype.slice() - JavaScript | MDN
The slice() method of String values extracts a section of this string and returns it as a new string, without modifying the original string. const str = "The quick brown fox jumps over the lazy dog."; console.log(str.slice(31)); // Expected output: "the lazy dog." console.log(str.slice(4, 19)); ...
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › String › split
JavaScript String split() - Divide String Into Array | Vultr Docs
November 11, 2024 - It's useful for extracting text separated by varying numbers of digits. The JavaScript split() function is an incredibly powerful tool for string manipulation, providing flexibility with minimal syntactic ...
🌐
ReqBin
reqbin.com › code › javascript › wyqvcilw › javascript-split-string-example
How do I split a string in JavaScript?
To split a string in JavaScript, you can use the string.split(separator, limit) method. The split() method splits the given string into an array of strings using "separator" as the delimiter.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-string-split-method
JavaScript String split() Method - GeeksforGeeks
The JavaScript split() method is used to break a string into an array of substrings based on a given separator.
Published   January 16, 2026
🌐
Flexiple
flexiple.com › javascript › javascript-split-string
JavaScript split string - String into substrings | Flexiple tutorial | JavaScript - Flexiple
March 11, 2022 - If a separator is not passed, the array will contain one element containing the entire string. let Flexiple = 'Hire top freelance developers' let week = 'Monday,Tuesday,Wednesday,Thursday,Friday,Saturday,Sunday' let flexiplelist = Flexiple.split(" ") let weeklist = week.split(",") let flexiplelist2 = Flexiple.split() let weeklist2 = week.split(",",3) console.log(weeklist) console.log(flexiplelist) console.log(flexiplelist2) console.log(weeklist2)
🌐
Programiz
programiz.com › javascript › library › string › split
JavaScript String split()
Returns an Array of strings, split at each point where the separator occurs in the given string. Note: The split() method does not change the original string. console.log("ABCDEF".split("")); // [ 'A', 'B', 'C', 'D', 'E', 'F' ] const text = "Java is awesome.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-split-string-by-index
Split a String at a specific Index using JavaScript | bobbyhadz
March 4, 2024 - To split a string at a specific index, use the `slice()` method to get the two parts of the string.
🌐
JavaScript in Plain English
javascript.plainenglish.io › how-to-split-a-string-once-in-javascript-3c3cfefe1321
How do you split a string once in JavaScript? | by John Au-Yeung | JavaScript in Plain English
June 10, 2024 - In this article, we’ll look at how to split a string once in our JavaScript code. To split a string once in our JavaScript code, we can use the JavaScript string’s indexOf method with the JavaScript string’s slice method to find the index of the first instance of the separator and then do the slicing.
🌐
JavaScript.info
javascript.info › tutorial › the javascript language › data types
Array methods
It returns a new array copying to it all items from index start to end (not including end). Both start and end can be negative, in that case position from array end is assumed. It’s similar to a string method str.slice, but instead of substrings, it makes subarrays.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › String › substring
String.prototype.substring() - JavaScript | MDN
The substring() method of String values returns the part of this string from the start index up to and excluding the end index, or to the end of the string if no end index is supplied.
🌐
Tabnine
tabnine.com › home › how to use split in javascript
How to Use split in JavaScript - Tabnine
July 25, 2024 - The split() method takes a string and returns an array of strings, splitting the original string based upon a provided separator character. This can be useful when only a certain portion of a string is required.