- <!DOCTYPE html>
- <html>
- <head>
- <title>
- test013_Array_prototype_unique()
- </title>
- </head>
- <script type="text/javascript">
- Array.prototype.unique = function() {
- var a = {};
- for (var i = 0; i < this.length; i++) {
- if (typeof a[this[i]] == "undefined")
- a[this[i]] = 1;
- }
- this.length = 0;
- for(var i in a)
- this[this.length] = i;
- return this;
- };
- </script>
- <script type="text/javascript">
- var a = [1,2,3];
- var b = [2,3,4];
- var c = a.concat(b).unique();
- console.log(c);
- </script>
- <body>
- </body>
- </html>
来源: http://www.bubuko.com/infodetail-2166371.html