How do I shuffle a Javascript Array ensuring each Index is in a new position in the new Array?
问题 I have an Array of Objects, like so. var usersGoing = [ { user: 0 }, { user: 1 }, { user: 2 }, { user: 3 }, { user: 4 } ]; I need to shuffle this Array so that no Object remains in the same index as when it was instantiated, like so: [ { user: 3 }, { user: 2 }, { user: 4 }, { user: 0 }, { user: 1 } ] It is IMPERATIVE that the resulting array be sorted in this manner, as each of these user Objects will be assigned to a different user Object. I have tried a few different sorting algorithms,