VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-shuffle-method/

⇱ Lodash _.shuffle() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.shuffle() Method

Last Updated : 3 Sep, 2024

Lodash _.shuffle() method creates an array of shuffled values from the given collection using a version of the Fisher-Yates shuffle algorithm.

Syntax

_.shuffle(collection);

Parameters:

  • collection: This parameter holds the collection to shuffle.

Return Value:

This method is used to return the new shuffled array.

Example 1: In this example, we are shuffling an array by the use of the _.shuffle() method.

Output:

[ 10, 9, 4, 2, 6 ]

Example 2: In this example, we are shuffling an array by the use of the _.shuffle() method.

Output:

[ 'sat', 'wed', 'fri', 'sun', 'thu', 'mon', 'tue']
Comment