This article mainly introduces the sample code for de-duplication and de-duplication of JS arrays. If you need it, you can refer to it for help.
Method 1: code for deduplication: <script> Array. prototype. distinct = function () {var a = [], B = []; for (var prop in this) {var d = this [prop]; if (d = a [prop]) continue; // prevents loops to prototype if (B [d]! = 1) {. push (d); B [d] = 1;} return a;} var x = ['A', 'B', 'C', 'D ', 'B', 'A', 'E', 'A', 'B', 'B', 'C', 'D', 'B', 'A ', 'E']; document. write ('original array: '+ x); document. write ("<br/>"); document. write ('after deduplication: '+ x. distinct (); </script> Method 2: the code for getting duplicate data is as follows: <script type = "text/javascript"> Array. prototype. distinct = function () {var a = [], B = [], c = [], d = []; for (var prop in this) {var d = this [prop]; if (d = a [prop]) {continue;} // prevents loops to prototype if (B [D]! = 1) {. push (d); B [d] = 1;} else {c. push (d); d [d] = 1 ;}// return a; return c. distinct1 ();} Array. prototype. distinct1 = function () {var a = [], B = []; for (var prop in this) {var d = this [prop]; if (d = a [prop]) continue; // prevents loops to prototype if (B [d]! = 1) {. push (d); B [d] = 1;} return a;} var x = ['A', 'B', 'C', 'D ', 'B', 'A', 'E', 'A', 'B', 'B', 'C', 'D', 'B', 'A', 'E ', 'F', 'F', 'G']; document. write ('original array: '+ x); document. write ("<br/>"); document. write ('after deduplication: '+ x. distinct (); </script>