\"you are How\" Those are the code I typed, it could reverse the st开发者_开发知识库ring ," />
开发者

Javascript - How to reverse a string and disappear those commas?

I want to reverse the string like this: "How are you" -> "you are How" Those are the code I typed, it could reverse the st开发者_开发知识库ring , but it still has comma between strings like "you,are,How"

var str = window.prompt("Enter a string");
var tokens = str.split( " " );


document.writeln( tokens.reverse() );


Use .join(" ")

var str = window.prompt("Enter a string"); var tokens = str.split( " " );
document.writeln( tokens.reverse().join(" ") );
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜