Array.prototype.unique = function(){ var result = []; // creat a variable to store the result var hash = {}; // create a hash element var type = null; this.forEach(function(e){ type = typeof(e); hash[e] || (hash[e] = []); // if current element is already in hash, do nothing. Otherwise create an attribute based on current element if(hash[e].indexOf(type) < 0) { result.push(e); hash[e].push(type); } }); return result; }