function removeDuplicates(arr) {
var temp = {};
for (var i = 0; i
temp[arr[i]] = true;
var r = [];
for (var k in temp)
r.push(k);
return r;
}
//Usage
var fruits = ['apple', 'orange', 'peach', 'apple', 'strawberry', 'orange'];
var uniquefruits = removeDuplicates(fruits);
//print uniquefruits ['apple', 'orange', 'peach', 'strawberry'];
var fruits = ['apple', 'orange', 'peach', 'apple', 'strawberry', 'orange'];<br>
Note 'orange' is duplicate in fruits array. Click to remove duplicate elements from fruits array:
<script><br />
function removeDuplicates(arr) {<br />
var temp = {};<br />
for (var i = 0; i < arr.length; i )<br />
temp[arr[i]] = true;<br />
var r = [];<br />
for (var k in temp)<br />
r.push(k);<br />
return r;<br />
}<br />
function check() {<br />
var fruits = ['apple', 'orange', 'peach', 'apple', 'strawberry', 'orange'];<br />
var uniquefruits = removeDuplicates(fruits);<br />
alert(uniquefruits);<br />
}<br />
</script>