// //倒序字符串的方法String.prototype.myReverse=function () { for(var i=this.length-1;i>=0;i--){ console.log(this[i]); }};var str="1234567";str.myReverse(); //为内置对象Array的原型对象中添加方法Array.prototype.mySort=function () { for(var i=0;i<this.length-1;i++){ for(var j=0;j<this.length-1-i;j++){ if(this[j]<this[j+1]){ var temp=this[j]; this[j]=this[j+1]; this[j+1]=temp; } } }};var arr=[100,30,40,200,50,80,60,7];arr.mySort();console.log(arr);
原文地址:https://www.cnblogs.com/lujieting/p/10066997.html
时间: 2025-01-07 13:45:34