Friday, February 6, 2026
HomeLanguagesJavascriptLodash_.shuffle() Method

Lodash_.shuffle() Method

The _.shuffle() method shuffles of collection by returning the new array.

Syntax: 

_.shuffle(collection)

Parameters: This method accepts a single parameter as mentioned above and described below:

  • collection: This parameter holds the collection to inspect.

Return Value: This method returns the new array after shuffling.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array and use _.shuffle() method
var gfg = _.shuffle([1, 2, 3,4]);
  
// Printing the output 
console.log(gfg);


Output :

[4, 1, 3, 2]

Example 2 :

Javascript




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array and use _.shuffle() method
var gfg = _.shuffle(["g", "e", "e", "k", "s", "f", "o",
                     "r", "g", "e", "e", "k", "s"]);
  
// Printing the output 
console.log(gfg);


Output :

["o", "e", "k", "s", "e", "e", "s",
 "g", "r", "e", "g", "f", "k"]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32489 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11983 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12073 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7236 POSTS0 COMMENTS
Thapelo Manthata
6946 POSTS0 COMMENTS
Umr Jansen
6930 POSTS0 COMMENTS