+ 11
[SOLVED] JavaScript - split() not working
I have a problem with split() method. It won't work. It should've been separated with commas but turns out it didn't separate each index with commas. https://code.sololearn.com/WYgHXme6x8P8/?ref=app
6 odpowiedzi
+ 6
var letter = "abc";
alert(letter.split(""));
Empty argument separate each symbol with commas.
+ 8
Let's say you have a string:
var result = "a,b,c"
result.split(',') will split the string to an array of substrings a, b, and c.
Now that your goal is to split the individual characters as substring, but your original string does not contain commas, all you have to do would be:
result.split('')
Also, you might want to assign the result of the split back to the variable:
result = result.split('')
+ 5
Thank you so much! Now, I got it. Hatsy Rei
+ 5
var letter = "abc";
result= letter.split("");
alert(result);
will actually put commas in between abc as a,b,c
+ 4
Thanks Alex Sol
+ 3
Hi. You have to pass separator to the .split(“|”) method even if it space .split(“ ”) or empty string .split(“”) because comma “,” is seperator by default. Enjoy