Code2night
  • Home
  • Guest Posts
  • Tutorial
  • Languages
    • Angular
    • C
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
  • Register
  • Login
  1. Home
  2. Blogpost

How to shuffle an array using javascript

Date- May 07,2022

5017

How to shuffle an array using javascript

Shuffling an array means we want to randomly rearranging the list or an array.

Using algorithms we use shuffle an array.

Algorithm:


Array =[11,12,13,14,15,16]

<button onclick="display()"> click </button> <script> // Function for array shuffling function ArrayShuffle(array) { for (var i = array.length - 1; i > 0; i--) { //random number generate var j = Math.floor(Math.random() * (i + 1)); var tempVar = array[i]; array[i] = array[j]; array[j] = tempVar; } return array; } //Showing result by this function function display() { var ary = [11,12,13,14,15,16] var ary1 = ArrayShuffle(ary) document.write("After shuffling Array: ", ary1) } </script>

Output

Before Shuffling
Array =[11,12,13,14,15,16]

After shuffling
After shuffling Array: 11,13,15,14,12,16

Algorithm:

This algorithms uses function that returns(random-0.5) as comparator to sort function.

 

Array =[11,12,13,14,15,16]

<button onclick="display()"> click </button>

Output

Before Shuffling
Array =[11,12,13,14,15,16]

After shuffling
After shuffling Array: 12,15,16,11,13,14

Comments

Tags

Swagger UI
Swashbuckle
SwashbuckleAspNetCore
Rest API
Postman
Api Testing
ITextSharp
Export to Pdf
AspNet Core
AspNet
C#
View to Pdf in Aspnet
Scheduler
Fibonacci series in Java
Display Fibonacci Series
First C# Program
What is C?
C
C Programming
CodeLobster
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp Join Us On Facebook
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, India   info@code2night.com

Quick Links
  • Home
  • Blogs
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • XML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • PDF Editor
By Language
  • Angular
  • C
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Built with for developers