let newArr = Array(10).fill().map(_ => value()) while (newArr[0] === 0) newArr[0] = value() alert(newArr) // function value() { return Math.round(Math.random() * 9) }