how to randomize an array
function randomArrayShuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var alphabet=["a","b","c","d","e"];
randomArrayShuffle(alphabet);
//alphabet is now shuffled randomly = ["d", "c", "b", "e", "a"]
const getShuffledArr = arr => {
const newArr = arr.slice()
for (let i = newArr.length - 1; i > 0; i--) {
const rand = Math.floor(Math.random() * (i + 1));
[newArr[i], newArr[rand]] = [newArr[rand], newArr[i]];
}
return newArr
};
Also in JavaScript:
- react make an ascending descending button
- random text generator javascript
- js array get index
- app.router.navigate reset framework7
- return uncommon from two arrays js
- Javascript compare two arrays
- add property with value in js
- express js post request body
- [SECURITY] node-uuid: crypto not usable, falling back to insecure Math.random()
- fetch
- javascript countdown 10 seconds
- array.unshift in javascript
- razor pages and javascript
- jspdf cdn
- file origin does not match viewer's pdf.js
- javascript sort object by key
- find method javascript
- mongodb delete user
- regular expression search for any character until Space
- data-dismiss= modal in jquery
- function that search a biggest value in array javascript
- javascript convert number from thousands to k and millions to m
- how to set text for label in jquery
- las element of object