What is the function of Array.reverse () in javascript
This article mainly explains "what is the function of Array.reverse () in javascript". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the function of Array.reverse () in javascript"?
Description
1. The Array.reverse () method reverses the order of the elements in the array and returns the array in reverse order.
2. Instead of creating a new array through the rearranged elements, rearrange it in the original array. This method changes the original array.
Example
Array.prototype.myReverse=function () {if (this instanceof Array) {/ / Array var len=this.length,i=len-1; var res= []; / define an array for (iBizi > = 0Bing iMurt -) {res.push (This [I]);} this.length=0;// empties the original array Array.prototype.splice.apply (this, [0mem0reres]) / / insert the new result into the original array, where the apply method is very suitable for} else {/ / processing class arrays var keys= [], values= []; var len=this.length; delete this ['length']; for (var k in this) {keys.push (k); values.push (This [k]);} for (var iMagne0)