- The first method: the use of JSON objects, if no JSON object is added, otherwise not added, and finally return the properties of the JSON object, the time complexity of O (n)
function deletearrayrepeat (arr) { var result = {}; var temp = []; // for (var i = 0; i < arr.length; i++ if (! = 0;
Temp.push (arr[i]); }} return temp; }
2. The second method uses the filter () method and the IndexOf () method. Because the filter method and the IndexOf method are essentially a layer for loop implementation, The time complexity is O (n*n); the code is as follows
function deletearrayrepeat (arr) { return arr.filter (function(item,i) { return arr.indexof (item) = = =i; } );
3.3rd method: using the indexof () method, the time complexity is O (n*n);
function deletearrayrepeat (arr) { var temp=[]; for (var i=0;i<arr.length;i++) { if(temp.indexof (arr[i]) ===-1) { Temp.push (arr[i]); } } return temp; }
Several methods for array de-weight-------javascript description