compare the size of the string in javascript

Can be used directly in JavaScript [>] or [<] operators compare two strings size, because this time JS interpreter will converted to ASCII character string character by character comparison sequentially.

var a = "1.2.2a";
var b = "1.2.2b";

console.log(a > b); // 输出true
console.log(a < b); // 输出false

a = "1.02.1";
b = "1.1";

console.log(a > b); // 输出false
console.log(a < b); // 输出true

Commonly used in the scene where usually relatively standard time format.

the console.log ( '2019-12-23'> '2019-12-20'); // prints true

 

"How far way to go, we want to see the scenery."

Guess you like

Origin www.cnblogs.com/yanggb/p/12077188.html