Last active
November 2, 2022 12:01
-
-
Save AysadKozanoglu/c19897e7073440a2989dbce993462680 to your computer and use it in GitHub Desktop.
shuffle json object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Aysad Kozanoglu | |
externData = [ | |
{ | |
"name": "cola", | |
"epreis": "1.50" | |
}, | |
{ | |
"name": "fanta", | |
"epreis": "1.60" | |
}, | |
{ | |
"name": "wasser", | |
"epreis": "1.70" | |
} | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Aysad Kozanoglu | |
<script src="data.json"></script> | |
<script> | |
function shuffle(a) { | |
var j, x, i; | |
for (i = a.length - 1; i > 0; i--) { | |
j = Math.floor(Math.random() * (i + 1)); | |
x = a[i]; | |
a[i] = a[j]; | |
a[j] = x; | |
} | |
return a; | |
} | |
newJsonShuffled = shuffle(externData); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice bro
Thanks for this block of code...