var arr = [1,2,3,2,1], temp = {}; temp = arr.filter(function(a) { return temp[a] || !(temp[a]=!0) }) alert(temp)