最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native localeCompare not working on Android - Stack Overflow

programmeradmin1浏览0评论

I am trying sort my array alphabetically.

myArray.sort(function(a, b){
    return a.title.localeCompare(b.title ,'tr');
  })

myArray includes turkish characters like 'ç,ş,ü,ö,ı'. My code works correctly on ios but it doesn't work the way i want it on android. It sort alphabatically but words starting with turkish characters are at the bottom of list.

I am trying sort my array alphabetically.

myArray.sort(function(a, b){
    return a.title.localeCompare(b.title ,'tr');
  })

myArray includes turkish characters like 'ç,ş,ü,ö,ı'. My code works correctly on ios but it doesn't work the way i want it on android. It sort alphabatically but words starting with turkish characters are at the bottom of list.

Share Improve this question edited Nov 7, 2018 at 13:45 user asked Nov 7, 2018 at 12:30 useruser 1231 silver badge11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

In recent versions of React Native, you can enable Intl support in your Android app by changing the value of jscFlavor in app/build.gradle to org.webkit:android-jsc-intl:+

The location to change the value in the gradle file

I'm having the same issue with latest RN 0.61.5 on Android.

I ended up using lodash deburr to remove accented chars from my strings and I then call String.localCompare on deburred strings. It seems to do the job so far...

发布评论

评论列表(0)

  1. 暂无评论