var arr = [9, 9, 9, 111, 5, 2, 3, 4, 4, 5, 5, 5, 7]; function fn(d, e) { for (var f = [], b = {}, a, c = 0; c < d.length; c++) a = d[c], b[a] >= e || (b[a]++ || (b[a] = 1), b[a] >= e && f.push(a)); return f }; alert(fn(arr, 3));