This question may look quite similar to [ ][1]Remove Duplicates from JavaScript Array, but it's really different: I need to find equal elements in array and delete them all, for example,
var arr1 = ["andesite", "grass", "dirt", "pink wool", "dead shrub", "grass"];
the result must be:
var arr1 = ["andesite", "dirt", "pink wool", "dead shrub"];
What I want is to find out that "grass" goes there twice, and exclude both from the array. I've tried something like
function inArray(arr){
var index = [];
var count = arr.length;
for(var i=0;i<count;i++){
if(arr[i] in index){
arr.splice([i],1);
}else{
index1.push(arr[i]);
}
}
return arr;
} but it removes only the second duplicating element when comparing it with the first one.
Thank you in advance for any responce. This is an educating task for me, so, I will highly appreciate explanations how it works.