2015-12-18 16 views
0

我有與字符串相同的數組,但他們it數組排序不正確,它從我的電腦複製。在瀏覽器中輸入items字符串在Javascript中排序不正確

https://jsfiddle.net/acc8xf0g/

var items = ["hard", "intermediate", "easy"]; 

var it = [ 
    "intermediate", 
    "hard", 
    "еasy" 
]; 

items.sort(function(a, b) { 
    return a.localeCompare(b); 
}); 

it.sort(function(a, b) { 
    return a.localeCompare(b); 
}) 

$("#test").html(items.join(" ")); 
$("#test2").html(it.join(" ")); 
+0

它實際上不是相同的數組。你從哪裏得到第二個數組? –

回答

3

看那it陣列中的 「E」 的實際十六進制值:

22 68 61 72 64 22 2c 20 22 69 6e 74 65 72 6d 65 |"hard", "interme| 
64 69 61 74 65 22 2c 22 65 61 73 79 22 0a  |diate","easy".| 


22 69 6e 74 65 72 6d 65 64 69 61 74 65 22 2c 20 |"intermediate", | 
22 68 61 72 64 22 2c 20 22 d0 b5 61 73 79 22 0a |"hard", "..asy".| 
+0

它實際上是西里爾字符。 https://en.wikipedia.org/wiki/Ye_(Cyrillic) –

相關問題