How to compare Unicode strings in Javascript?

后端 未结 6 2031
不知归路
不知归路 2020-11-29 21:34

When I wrote in JavaScript \"Ł\" > \"Z\" it returns true. In Unicode order it should be of course false. How to fix this? My site i

6条回答
  •  旧巷少年郎
    2020-11-29 22:15

    Funny, I have to think about that problem and finished searching here, because it came in mind, that I can use my own javascript module. I wrote a module to generate a clean URL, therefor I have to translitate the input string... (http://pid.github.io/speakingurl/)

    var mySlug = require('speakingurl').createSlug({
        maintainCase: true,
        separator: " "
    });
    
    var input = "Schöner Titel läßt grüßen!? Bel été !";
    var result;
    
    slug = mySlug(input);
    console.log(result); // Output: "Schoener Titel laesst gruessen bel ete"
    

    Now you can sort with this results. You can ex. store the original titel in the field "title" and the field for sorting in "title_sort" with the result of mySlug.

提交回复
热议问题