You can use the split()
function to turn the string into an array of single characters, and then the join()
function to turn that back into a string where you specify a joining character (specifying space as the joining character):
function insertSpaces(aString) {
return aString.split("").join(" ");
}
(Note that the parameter to split()
is the character you want to split on so, e.g., you can use split(",")
to break up a comma-separated list, but if you pass an empty string it just splits up every character.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…