ตัวอย่าง
ตรวจสอบว่าสตริงลงท้ายด้วย "จักรวาล."
var str = "Hello world, welcome to the universe.";
var n = str.endsWith("universe.");
ผลของ N จะเป็น:
true
ลองตัวเอง» เพิ่มเติม "ลองตัวเอง" ตัวอย่างด้านล่าง
ความหมายและการใช้งาน
endsWith()
วิธีการกำหนดว่าสตริงลงท้ายด้วยตัวอักษรของสตริงที่ระบุ
วิธีการนี้จะส่งกลับ true
ถ้าสตริงลงท้ายด้วยตัวอักษรและ false
ถ้าไม่ได้
หมายเหตุ: endsWith()
วิธีการเป็นกรณีที่สำคัญ
สนับสนุนเบราว์เซอร์
วิธี | |||||
---|---|---|---|---|---|
endsWith() | 41 | 12.0 | 17 | 9 | 36 |
วากยสัมพันธ์
string.endsWith( searchvalue , length )
ค่าพารามิเตอร์
Parameter | Description |
---|---|
searchvalue | Required. The string to search for |
length | Optional. Specify the length of the string to search. If omitted, the default value is the length of the string |
รายละเอียดทางเทคนิค
กลับค่า: | บูลีน ผลตอบแทน true ถ้าสตริงลงท้ายด้วยค่ามิฉะนั้นก็จะส่งกลับ false |
---|---|
JavaScript เวอร์ชัน: | ECMAScript 6 |

ตัวอย่างเพิ่มเติม
ตรวจสอบว่าสตริงลงท้ายด้วย "โลก" สมมติว่าสตริงเป็น 11 ตัวอักษร:
var str = "Hello world, welcome to the universe.";
var n = str.endsWith("world", 11);
ผลของ N จะเป็น:
true
ลองตัวเอง» 