标签:javascript
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" charset="UTF-8"> var arr = [1,2,3,2,3,4,5,6,7,8,9,8,5]; //将数组转换成对象 //利用对象的key值不能重复这一特性 var toObject = function(array) { var obj = {}; for(var i=0,j=array.length;i<j;i++){ obj[array[i]] = true; } return obj; } //再将对象转换成数组 var toArray = function(obj){ var arr = []; for(var i in obj){ arr.push(i); } return arr; } //综合前两者,完成去数组重复项方法 var uiq = function(arr){ return toArray(toObject(arr)); } var arr1 = uiq(arr); console.log(arr1); </script> </head> <body> </body> </html>
标签:javascript
原文地址:http://blog.csdn.net/liuao107329/article/details/45719053