Skip to content

Instantly share code, notes, and snippets.

@AysadKozanoglu
Last active November 2, 2022 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AysadKozanoglu/c19897e7073440a2989dbce993462680 to your computer and use it in GitHub Desktop.
Save AysadKozanoglu/c19897e7073440a2989dbce993462680 to your computer and use it in GitHub Desktop.
shuffle json object
// Author: Aysad Kozanoglu
externData = [
{
"name": "cola",
"epreis": "1.50"
},
{
"name": "fanta",
"epreis": "1.60"
},
{
"name": "wasser",
"epreis": "1.70"
}
]
// 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>
@tamil-programmer
Copy link

Nice bro
Thanks for this block of code...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment