Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Shuffle a Sting in JavaScript

var shuffled = str.split('').sort(function(){return 0.5-Math.random()}).join('');
Comment

javascript shuffle string

String.prototype.shuffle = function () {
    var a = this.split(""),
        n = a.length;

    for(var i = n - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
    }
    return a.join("");
}
console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "veolrm  hth  ke opynug tusbxq ocrad ofeizwj"

console.log("the quick brown fox jumps over the lazy dog".shuffle());
//-> "o dt hutpe u iqrxj  yaenbwoolhsvmkcger ozf "
Comment

PREVIOUS NEXT
Code Example
Javascript :: sortby vue 
Javascript :: remove local storage item 
Javascript :: table in text 
Javascript :: Javascript how to differentiate single click event and double click event 
Javascript :: react add inline styles in react 
Javascript :: Count frequency of array elements js 
Javascript :: epsilon javascript 
Javascript :: get table row data jquery 
Javascript :: strapi change user password 
Javascript :: custom attribute jquery selector 
Javascript :: get data from formdata 
Javascript :: javascript date to firebase timestamp 
Javascript :: javascript how to check if array is empty 
Javascript :: capitalize first letter of string javascript 
Javascript :: transpose of the matrix in javascript 
Javascript :: react best libraries for Modern UI 
Javascript :: kotlin jsonobject from string 
Javascript :: how to add up all the numbers in between 0 and that number 
Javascript :: js select div 
Javascript :: jquery active menu 
Javascript :: bs modal service close 
Javascript :: add active class and remove active class by click 
Javascript :: google sheets api javascript 
Javascript :: iterate over array of objects javascript 
Javascript :: protected route in react js 
Javascript :: react input number validation 
Javascript :: gatsby new 
Javascript :: express get query parameters 
Javascript :: http to https redirect express js 
Javascript :: js copy to clipboard 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =