javascript - How to randomly iterate through an array once, and then repeatedly iterate in that order -
This is my array: arr = [0, 1, 2, 3, 4, 5]
I randomly want to iterate for the first time and after that I want to repeat the same (random) order again. How will I do this? I can think that the only way to throw AR is to use it in some way and then it will be repeated gradually. For example:
newArr = shif (arr); For (j = 0; j & lt; 5; j ++) {for (i = 0; i & lt; newArr.length; i ++)}
I think Is there any easy, inline way, so that if the item is added to the array then I do not have to reshape (and every time a new array
)
Create a second array. Next, populate the array with the random number (ranging from 0 to array.length
). Now make a loop to repeat through the secondary array. Each number in the array corresponds to an index in the array
.
Result: You can now randomly iterate without modifying the command through the
. array
array
Later you can use the splice ()
function to add to the other array at random points (and push ()
main To add to the array
).
Comments
Post a Comment