How JavaScript removes duplicate values from the array:
Arrays are used to organize data, and sometimes the data is duplicated, and here's how to remove duplicate content from the array.
The code example is as follows:
varthearray=[1,2,3,4,5,6,4,3,10];functionUnique (data) {vardata=data| |[]; varA={}; for(vari=0;i<data.length;i++){ varv=Data[i]; if(typeof(A[v]) = = ' undefined ') {A[v]=1; }} data.length=0; for(varIincha) {Data[data.length]=i; } returndata;} Console.log (Unique (TheArray));
The above code can output an array element after removing duplicate content. Of course there are many ways to implement this feature, and this section describes only this one, which is the implementation process described below.
Implementation principle:
The principle is actually very simple, first establish an empty object A, and then iterate through each element in the array, and the element value of the array as an attribute of object A, if this property does not exist, and then add this property for object A and assign a value of 1, so that the non-repeating array elements become object a properties, and finally through the for The in element iterates through each property and adds it to the array so that it implements the function we want.
The original address is: http://www.51texiao.cn/javascriptjiaocheng/2015/0522/2247.html
The most original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9273
How JavaScript removes duplicate values from an array