The
d3.shuffle() function in D3.js is used to randomize or shuffle the order of the given array elements in place and returns the array.
Syntax:
d3.shuffle( Array, start, stop )
Parameters: This function accepts three parameters as mentioned above and described below:
- Array: This parameter holds the array elements.
- start: It represents the starting index of array to shuffle the array elements. It start value not specifies then it takes zero as default value.
- stop: It represent the ending index of array to shuffle the array elements. Its default value is the length of array.
Return Value: It returns the array of shuffled elements.
Below programs illustrate the d3.shuffle() function in D3.js:
Example 1:
Output:
2, 3, 1, 4
20, 40, 10, 30
11, 9, 5, 7
2, 10, 4, 8, 6
Example 2: