Home >Web Front-end >JS Tutorial >How to reverse string in javascript_javascript skills
The example in this article describes how to achieve string reversal in JavaScript. Share it with everyone for your reference. The specific implementation method is as follows:
//变量交换 方法 var a=0,b=1,c=2; a=[b,b=c,c=a][0]; //正文 var array='abcdefgh'; function Reverse(arr){ var arr1=arr.split('');//[a,b,c,d,e,f,g] var halfLen=Math.floor(arr.length/2);//3 alert(halfLen) var len=arr.length;//7 var s=0; for(s=0;s<=halfLen;s++){ arr1[s]=[arr1[len-s],arr1[len-s]=arr1[s]][0] } alert(arr1.join('')) } Reverse(array)
I hope this article will be helpful to everyone’s JavaScript programming design.