Reverse strings without changing the order of words in a sentence

前端 未结 4 1540
心在旅途
心在旅途 2020-12-20 22:25

My Code:

I tried the following code but the order of words are changing

var str = \"Welcome to my Website !\";

alert(str.split(\"\").reverse().join(         


        
4条回答
  •  遥遥无期
    2020-12-20 23:12

    Use this:

    var str = "Welcome to my Website !";
    alert(str.split("").reverse().join("").split(" ").reverse().join(" "));
    

提交回复
热议问题