This article describes the method of implementing string inversion in JavaScript. Share it for your reference. The specific implementation method is as follows:
//Variable exchange method var a=0,b=1,c=2;a=[b,b=c,c=a][0];//Text 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.