Remove accents/diacritics in a string in JavaScript

前端 未结 29 2528
轻奢々
轻奢々 2020-11-21 13:29

How do I remove accentuated characters from a string? Especially in IE6, I had something like this:

accentsTidy = function(s){
    var r=s.toLowerCase();
           


        
29条回答
  •  心在旅途
    2020-11-21 13:56

    You can use the _.deburr() method from the Lodash library.

    It's available as a stand-alone NPM package lodash.deburr, or as part of the lodash package.

    const myStringWithAccent = 'Mon café est plein de caféïne';
    const myStringWithoutAccent = _.deburr( myStringWithAccent, );
    

    The result will be : "Mon cafe est plein de cafeine"

提交回复
热议问题