+ 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

28th Oct 2018, 1:24 AM
ᴰᴼᴹᴵᴺᴼ
ᴰᴼᴹᴵᴺᴼ - avatar
6 odpowiedzi
+ 6
var letter = "abc"; alert(letter.split("")); Empty argument separate each symbol with commas.
28th Oct 2018, 1:37 AM
Alex Sol
+ 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('')
28th Oct 2018, 1:38 AM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Thank you so much! Now, I got it. Hatsy Rei
28th Oct 2018, 1:39 AM
ᴰᴼᴹᴵᴺᴼ
ᴰᴼᴹᴵᴺᴼ - avatar
+ 5
var letter = "abc"; result= letter.split(""); alert(result); will actually put commas in between abc as a,b,c
28th Oct 2018, 2:30 AM
BroFar
BroFar - avatar
+ 4
Thanks Alex Sol
28th Oct 2018, 1:38 AM
ᴰᴼᴹᴵᴺᴼ
ᴰᴼᴹᴵᴺᴼ - avatar
+ 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
28th Oct 2018, 10:05 PM
Sergei No
Sergei No - avatar