The _.shuffle() function shuffles a collection.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Lodash _.shuffle() Method Example
<!DOCTYPE html> <html> <head> <title>Lodash Tutorial</title> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script> <script type="text/javascript"> words = ['sky', 'wood', 'forest', 'falcon', 'pear', 'ocean', 'universe']; console.log(_.shuffle(words)); console.log(_.shuffle(words)); console.log(_.shuffle(words)); console.log(words); </script> </head> <body></body> </html>
Output:
["universe", "pear", "ocean", "sky", "wood", "falcon", "forest"] ["forest", "pear", "ocean", "falcon", "wood", "universe", "sky"] ["ocean", "sky", "wood", "universe", "pear", "forest", "falcon"] ["sky", "wood", "forest", "falcon", "pear", "ocean", "universe"]
Comments
Post a Comment