Instead of using that large array, simply use [1,2,3,4,5].shuffle(). This way, you won't get duplicatesduplicates. But here's a function that will give you a unique array, i.e., an array without duplicates:
function unique(arr) { var result = [], map = {}; for (var i = 0; i < arr.length; i++) { var duplicate = map[arr[i]]; if (!duplicate) { result.push(arr[i]); map[arr[i]] = true; } } return result; } Then, just use unique(tempArray.shuffle()).
Here's a DEMO.