In practical applications, we may need to remove repeating elements from the array in many cases, and the following is the method implementation of the JavaScript array to weight:
<script language= "JavaScript" >
<!--
/* methods to determine if 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;
}
/* Remove duplicate elements from 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,4,1,3];
Origarr = distinct (Origarr);
alert (Origarr);
-->
</script>
Above this JavaScript to remove the array of repeating elements of the implementation of the "example" is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.