I want to remove elements that occurr more than once and get the unique element. The array always has 3 elements. Lets say i have an array [2,3,2], then I need to get 3 which is only unique in the array(removing both 2s, because they occur more than once).
I have tried with following code, but surely it doesnot work as expected.
var firstArrTemp = [2,3,2];
var sorted_arr = firstArrTemp.sort();
var unique_element;
for (var i = 0; i < sorted_arr.length - 1; i++) {
if (sorted_arr[i + 1] != sorted_arr[i]) {
unique_element=sorted_arr[i];
}
}
alert(unique_element);
Thanks!
See Question&Answers more detail:os