JavaScript String slice() စနစ်
- အခြားစား search()
- နောက်ပိုင်းစား split()
- အထိပ်သို့ ပြန် JavaScript String ဂရမ်မောင်း စာရင်း
အသုံးပြုခြင်း နှင့် လက်ခံမှု
slice()
စနစ် က သတင်းစကား အစိတ်အပိုင်း တစ် ခု ကို ရယူလာသည်
slice()
စနစ် က တခုခု သတင်းစကား အစိတ်အပိုင်း ကို ခွဲခြား ပြန် ပေးသည် သော်လည်း အစိတ်အပိုင်း ပြင်ဆင် လာသည်
start နှင့် end ပြင်ဆင်သည့် သတင်းစကား အစိတ်အပိုင်း ကို အသုံးပြုသည်
ပထမ နေရာ ၀ ဖြစ်၍ ဒုတိယ နေရာ ၁ ဖြစ်သည်...
မှီးသား တုံ့ရှိ သည် သတင်းစကား အဆုံး မှ ရယူလာသည်
အခြား သဘောတူညွှန်း
အမှတ်ပြ
အကြောင်း ၁
ပြင်ဆင်မှု ၅ ခုမှ သိမ်းဆည်းပါ
let text = "မြန်မာဘာသာ!"; let result = text.slice(0, 5);
let result = text.slice(0, 5);
Example 2
From position 3 to the end:
Example 3
From position 3 to 8:
let result = text.slice(3, 8);
Example 4
Only the first character:
let result = text.slice(0, 1);
Example 5
Only the last character:
let result = text.slice(-1);
Example 6
The entire string:
let result = text.slice(0);
Syntax
string.slice(start, end)
parameter
parameter | description |
---|---|
start |
required. Starting position. The first character is 0. |
end |
optional. End position (at most, but not including). default is the length of the string. |
return
type | description |
---|---|
String | the extracted part of the string. |
Technical details
parameter start
is the starting index of the fragment to be extracted. If it is negative, then this parameter specifies the position from the end of the string. That is, -1 is the last character in the string, -2 is the second-to-last character, and so on.
parameter end
is the index of the end of the next fragment to be extracted. If this parameter is not specified, then the substring to be extracted includes start to the end of the original string. If the parameter is negative, then it specifies the position from the end of the string. If the parameter is negative, then it specifies the position from the end of the string. That is, -1 is the last character in the string, -2 is the second-to-last character, and so on.
return
အချက်အလက် string အခြေခံ စာလုံး စက်ဝိုင်း start from startto end အဆုံး(အပါအဝင် မပါ) end)အထိ စာလုံး စက်ဝိုင်း ကို ပြန်လည် ပေးပါ
ဖော်ပြ
slice() စနစ် က စာလုံး စက်ဝိုင်း ကို ပြန်လည် ပေးပါ string အချက်အလက် အစုစာတွဲ စာလုံး ကို ပြန်လည် ပေးပါ သို့မဟုတ် သက်သော အစုစာတွဲ ကို ပြန်လည် ပေးပါ သော်လည်း ထို စနစ် က ပြန်လည် ပြောင်းလဲ လိမ့်မည် string。
String အဖွဲ့ စနစ် slice()
、substring()
နှင့် substr()
(ကျန်းမြင်ချက် မပါ)အား ဖြင့် စာလုံး စက်ဝိုင်း ကို ပြန်လည် ပေးပါslice()
နှင့် substring()
အလုံး အချင်း ပြောင်းလဲ လိုက် ပါslice()
နှင့် substr()
မတူညီ သည် ကို စာလုံး စက်ဝိုင်း နှင့် အကွက် အား သုံးပြီး သက်သော အစုစာတွဲ ကို သတ်မှတ်ပါ substr()
ကို စာလုံး စက်ဝိုင်း နှင့် အကွက် အား သုံးပြီး သက်သော အစုစာတွဲ ကို သတ်မှတ်ပါ
ရှိသော အချက်ကိုString.slice()
နှင့် Array.slice()
တူညီ
ဘရပ်သား ထောက်ပံ့
slice()
ECMAScript1 (ES1) သဘောတရားဖြစ်သည်。
အားလုံး ဘရပ်သား တို့ အပြီးတိုင်း အားကောင်းစွာ ထောက်ပံ့သည် ES1 (JavaScript 1997):
ခလီ | အိုင်အို | အိန်ဂျက် | ဖရက်ခ် | ဆာဖာ | အိုပရာ |
---|---|---|---|---|---|
ခလီ | အိုင်အို | အိန်ဂျက် | ဖရက်ခ် | ဆာဖာ | အိုပရာ |
ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ | ထောက်ပံ့ |
- အခြားစား search()
- နောက်ပိုင်းစား split()
- အထိပ်သို့ ပြန် JavaScript String ဂရမ်မောင်း စာရင်း