<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" content="text/html" name="01"> <title>利用json去重 原型--实现继承</title> </head> <body> <script> //利用json去重 原型--实现继承 var arr = [1,2,4,3,45,6,33,4,2,6,"a"]; Array.prototype.quchong=function(){ var newArr=[]; var json={}; for(var i=0;i<this.length;i++){ if(!json[this[i]]){ newArr.push(this[i]); json[this[i]]=true; } } return newArr; }; var unq = arr.quchong(); document.write(unq); document.write('<br>'); //排序 unq.sort(function compare(a,b){ return a-b; //倒序 b-a }); document.write(unq);//利用splice 索引值删除字母 document.write('<br>'); unq.splice(7); document.write(unq); </script> </body> </html>
利用json去重 原型--实现继承
最新推荐文章于 2022-09-11 18:12:23 发布