JS Array.reverse elements of an array in reverse order

<pre><script type="text/javascript">

// JS Array.reverse array elements in the reverse order
// in JavaScript, reverse Array Objects () method of the reverse order (reversed) elements in the array. arr.reverse () function to achieve this in the original array, that is, reverse () will change the original array.
// Example. 1:
var ARR = [ "F", "E", "I", "E", "S", "O", "F", "T"];
document.writeln (arr.join ( )); // output: F, E, I, E, S, O, F, T
// inversion
arr.reverse ();
document.writeln (arr.join ()); // output: t, f , O, S, E, I, E, F
// ==================================== ================================================== ============
// Example 2: reverse string
String.prototype.reverse = function () {
 var A = [];
 for (var I = 0; I <. 9; I ++) {
  a.unshift (the this [I]);
 }
 return a.join ( "");
}
var STR = "feiesoft";

//==================================================================================================
//例3:反转数字
Number.prototype.reverse = function(){
 var s = this.toString();
 var a = [];
 for(var i=0;i<9;i++){
  a.unshift(s[i]);
 }
 return a.join("");
}
var num = 12345678;
document.writeln(num.reverse()); // 输出:87654321

</script></pre>

Forward article, the original link: https://blog.csdn.net/binggoogle/article/details/50847568

Guess you like

Origin www.cnblogs.com/diyunfei/p/11119711.html