How to remove duplicates in JavaScript Array
This article mainly introduces how JavaScript arrays can be de-weighted. It has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Method 1: set: not a data type, a data structure; unique member let arr = [12,1,12,3,1,88,66,9,66];function unique(ary) { let s = new Set(ary); // Array.from : convert the set data structure to a real array; return Array.from(s) } unique(arr); method 2: object attribute name cannot be repeated let arr = [12,1,12,3,1,88,66,9,66];function unique(ary) { let obj = {}; for(let i=0;i