开发者

Add a space between characters in a String [duplicate]

This question already has answers here:开发者_运维百科 Closed 11 years ago.

Possible Duplicate:

String Manipulation - Javascript -

I have a string:

hello

and I want to add a space between each character to give:

h e l l o

What is the best way to do this?


"hello".split('').join(' '); // "h e l l o"


var text = "hello";
var betweenChars = ' '; // a space

alert(text.split('').join(betweenChars));


try:

var hello = 'hello';
var test = '';

for(var i=0; i<hello.length; i++){
   test += hello.charAt(i) + ' ';     
}

alert(test);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜