JavaScript String slice() পদ্ধতি
- 上一页 search()
- 下一页 split()
- 返回上一层 JavaScript String পরামর্শ হান্ডবুক
সংজ্ঞা ও ব্যবহার
slice()
পদ্ধতি স্ট্রিংর একটি অংশ উপস্থাপিত করে。
slice()
পদ্ধতি একটি নতুন স্ট্রিংর রূপে উপস্থাপিত করে, প্রথম স্ট্রিংকে কম করে না।
start এবং end পারামিটার প্রদান করা হয় যাতে স্ট্রিংর কোনও অংশ উপস্থাপিত করা হয়。
প্রথম স্থান 0, দ্বিতীয়টি 1, ...
নেতিবাচক সংখ্যা স্ট্রিংর শেষ থেকে বের করা হয়。
অন্যান্য পঠনসূত্র:
উদাহরণ
উদাহরণ 1
আগের 5টি স্থান কাটা:
let text = "Hello world!"; 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. |
ফলাফল
Type | Description |
---|---|
String | The extracted part of the string. |
Technical Details
Parameter start
This parameter is the starting index of the segment to be extracted. If it is negative, it specifies the position from the end of the string. That is, -1 refers to the last character of the string, -2 refers to the second last character, and so on.
Parameter end
This parameter is the index of the end of the segment to be extracted. start to the end of the original string. If this parameter is negative, it specifies the position from the end of the string.
ফলাফল
একটি নতুন স্ট্রিং string from start ভাবে (অন্তর্ভুক্ত) 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 পরামর্শ হান্ডবুক