Shuffle an array in javascript

This code snippet can be use to Shuffle an array in JavaScript.

working example : http://jsfiddle.net/grainier/J4BuD/

  • James

    How to remove the , (comma) from the result?

    • If we print an Array in JavaScript, it automatically calls Array.toString(); method. This toString() method will return a string that separates the elements in the array with commas. (ie : a,b,c,d)

      But if you want to use another separator instead of a comma, you can explicitly call Array.join() method. This join() method takes a separator as a parameter. Then elements in the Array will be separated by that specified separator. The default separator is comma (,). (ie : if you use Array.join(‘+’), it will return a+b+c+d)