views:

60

answers:

1

I want to reverse the string like this: "How are you" -> "you are How" Those are the code I typed, it could reverse the string , 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() );

+4  A: 

Use .join(" ")

var str = window.prompt("Enter a string"); var tokens = str.split( " " );
document.writeln( tokens.reverse().join(" ") );
silent
Thank you so much!!!
Programme Newbie
no problem and welcome to stackoverflow!
silent