Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sort boolean value

a = [false, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false];
    
    
    a.sort(function(x, y) {
        // true values first
        return (x === y)? 0 : x? -1 : 1;
        // false values first
        // return (x === y)? 0 : x? 1 : -1;
    });
    
    console.log(a);
Comment

PREVIOUS NEXT
Code Example
Javascript :: nodejs string to base64 
Javascript :: javascript select element with attribute 
Javascript :: select element by id js 
Javascript :: phone number validation in yup 
Javascript :: chart js hide legend 
Javascript :: z index style javascript 
Javascript :: how to make a property important in javascript 
Javascript :: content type json 
Javascript :: js start with 
Javascript :: javascript padstart 
Javascript :: jquery set checkbox checked unchecked 
Javascript :: javascript write in id 
Javascript :: regex for numbers and decimals only 
Javascript :: fs check if dir is dir 
Javascript :: sort array of object js 
Javascript :: las element of object 
Javascript :: clone object in js 
Javascript :: how to get session value using javascript 
Javascript :: Appium press Enter on android with js 
Javascript :: jquery continue each loop 
Javascript :: before send ajax loading 
Javascript :: html div scroll 
Javascript :: jquery smooth scrool 
Javascript :: automatically add typedef to module.exports vscode site:stackoverflow.com 
Javascript :: js stop form submit on enter 
Javascript :: how to check element has an attribute js 
Javascript :: js regex email 
Javascript :: javascript base64 encode string 
Javascript :: camera helper three js 
Javascript :: sort by date js 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =