var arr = [9, 9, 9, 111, 5, 2, 5, 3, 4, 4, 5, 7]; var res = arr.filter(function(value, index){ return index != arr.indexOf(value) && index != arr.lastIndexOf(value); }); alert(res);