How to remove repeated array elements in javascript [instance], javascript Array
In practical applications, we often need to remove repeated elements from the array. below is the implementation of de-duplication of javascript Arrays:
<Script language = "javascript"> <! --/* Method for determining whether an element exists in an array */function isExistInArr (_ array, _ element) {if (! _ Array |! _ Element) return false; if (! _ Array. length) {return (_ array = _ element);} for (var I = 0; I <_ array. length; I ++) {if (_ element = _ array [I]) return true;} return false ;} /* method for removing repeated elements in the array */function distinct (_ array) {if (! _ Array |! _ Array. length) return _ array; var newArray = new Array (); for (var I = 0; I <_ array. length; I ++) {var oEl = _ array [I]; if (! OEl | this. isExistInArr (newArray, oEl) continue; newArray [newArray. length] = oEl;} return newArray;} var origArr = [1, 2, 3, 4, 1, 3]; origArr = distinct (origArr); alert (origArr ); // --> </script>
The implementation method [Example] for removing array repeated elements in the above javascript is all the content shared by xiaobian. I hope to give you a reference, and I hope you can provide more support to the customer's house.