标签:charset set index 方法 javascrip cti 数组去重 body dex
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用对象方法实现数组去重</title> </head> <body> <script> Array.prototype.unique = function() { var newArr = []; for(var i = 0;i<this.length;i++) { if(newArr.indexOf(this[i]) == -1) { newArr.push(this[i]); } } return newArr; }; var arr = [1,3,1,2]; console.log(arr.unique()); </script> </body> </html>
标签:charset set index 方法 javascrip cti 数组去重 body dex
原文地址:http://www.cnblogs.com/terry6/p/6822346.html