var arr = [1, 2, 1, 10, 5, 3, 4, 40, 50], bound = '\n\n===@@@==\n\n', tststr = bound + arr.join(bound+bound) + bound, out=[]; for (var i = 0; i < arr.length; i++) { if(tststr.split(bound +arr[i] + bound).length <3)out.push(arr[i]) } alert(out)