Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Splitting up a a whole string and add spacing?

This might be a dumb question, but how to I add space gaps using split. I know it returns as an array, so I am not sure if its what I want to do. But this is what I am using right now:

         var GetME = $("#textinput").val().split(" ");

So for example, give if the user inputs TEXTTEST, I want the GetMe var to hold T E X T T E S T, is this possible?

Thanks Glenn

like image 429
Glenn Curtis Avatar asked Apr 07 '26 06:04

Glenn Curtis


1 Answers

Use split("") without the space to break up the string into the array. If you want to add spaces in between each letter, use join(" ")

"abcdefghij".split("");            //["a","b","c","d","e","f","g","h","i","j"]
"abcdefghij".split("").join(" ");  // "a b c d e f g h i j"
like image 171
epascarello Avatar answered Apr 08 '26 21:04

epascarello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!