What is the best way to remove a specific number from an array in this scenario? There are 9 numbers stored in the array named nums and an empty array called narr. The goal is to randomly select an index (let's call it rand) from nums, remove that number from nums, and add it to narr. I have tried using methods like pop, splice, slice but none of them seem to give the correct answer. Can you suggest the most effective method?
function sudoku(arr){
let nums = [1,2,3,4,5,6,7,8,9];
let narr = [];
for(let i = 0; i<9; i++){
let rand = Math.floor(Math.random()*nums.length);
narr.push(nums[rand]);
nums.pop(nums[rand]);
}
return narr;
}