var range = [1, 2, 3, 4, 5, 6, 7, 8, 9]; var stack = []; while(range.length) { var index = Math.random() * range.length >> 0; var item = range.splice(index, 1)[0]; stack.push(item); } alert(JSON.stringify(stack));