let arr = [0,1,2,3...10]; if(arr.length) { let id = Math.floor(Math.random()*arr.length); id = arr.splice(id, 1, 0)[0]; }