JavaScript Remove duplicates from Array – Example Code

Here is the code to remove duplicates from an Array:

var distinctVal = function(arr){
var newArray = [];
for(var i=0, j=arr.length; i<j; i++){
if(newArray.indexOf(arr[i]) == -1)
newArray.push(arr[i]);
}
return newArray;
};