JavaScript String localeCompare()
ဥပမာများ
"ab" ကို "cd" နှင့် နှိုင်းယှဉ်ပါ-
let text1 = "ab";
let text2 = "cd";
let result = text1.localeCompare(text2);
let text1 = "cd";
let text2 = "ab";
let result = text1.localeCompare(text2);
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်းသည် လက်ရှိ localeCompare()
ဒေသရှိ လိုင်းနှစ်ခုကို နှိုင်းယှဉ်သည်။
localeCompare()
နည်းလမ်းသည် စီစဥ်မှု -1၊ 1၊ သို့မဟုတ် 0 (ရှေ့၊ နောက်၊ သို့မဟုတ် တန်းတူ) ကို ပြန်ပေးသည် ။
လက်ရှိနေရာသည် ဘရောက်ဆာ၏ ဘာသာစကားဆက်တင်များအပေါ် အခြေခံထားသည်။
အထားအသို
string.localeCompare(compareString)
ကန့်သတ်ချက်များ
Parameter | Description |
compareString | Required. The string to compare with. |
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
နံပါတ်တစ်ခု | တန်ဖိုး 3 ခု အနက်မှ တစ်ခု- 1 သည် comparisonString 0 မတိုင်မီ မျဉ်းကြောင်းကို စီမည်ဆိုပါက string နှစ်ခုသည် 1 နှင့် ညီပါက |
နောက်ထပ် ဥပမာများ
let text1 = "ab";
let text2 = "ab";
let result = text1.localeCompare(text2);
let text1 = "A";
let text2 = "a";
let result = text1.localeCompare(text2);
Browser ပံ့ပိုးမှု
localeCompare()
ECMAScript1 (ES1) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ES1 (JavaScript 1997) ကို ဘရောက်ဆာအားလုံးတွင် အပြည့်အဝ ပံ့ပိုးထားသည်။
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |