var newStr = ''; var array = [1,2,3,4,1,2,6,7]; for (var i in array) { for (var j in array) { if (array[i] != array[j]) { newStr += array[i]; } } } alert(newStr);