Giacomo Balli profile picture
Giacomo Balli
Complex decisions. Clear thinking.

I help business owners find new ways to make money with technology, and get the big technology decisions right.
Fluent in business. Grounded in technology. Paid only by you.

Let’s Talk It Through LinkedIn

Building technology products since 2010 · 100+ apps

Shuffle an Array in Random Order

This code sample will allow you to randomize (shuffle) the order of an array of objects, strings or numbers.

function shuffle(o) {
    for (var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
}

Directions:
- call myArray=shuffle(myArray);

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:49:51
Back to Blog