---
title: endsWith – ฟังก์ชันตรวจสอบว่าข้อความสิ้นสุดด้วยข้อความที่กำหนด
url: https://www.thepexcel.com/functions/n8n/string-functions/ends-with-n8n/
type: function-explainer
program: n8n
syntax: "endsWith(text, searchString)"
date: 2025-12-16
updated: 2025-12-17
scores:
  popularity: 7
  difficulty: 2
  usefulness: 7
---

# endsWith – ฟังก์ชันตรวจสอบว่าข้อความสิ้นสุดด้วยข้อความที่กำหนด

> ตรวจสอบว่าข้อความสิ้นสุดด้วยข้อความที่กำหนด

## คำอธิบาย

endsWith ตรวจสอบว่าข้อความสิ้นสุดด้วยข้อความที่ระบุหรือไม่ ส่งคืนค่า true หรือ false ฟังก์ชันนี้มีประโยชน์ในการตรวจสอบนามสกุลไฟล์ ส่วนท้ายข้อความ หรือการจำแนกประเภท

## Syntax

```excel
endsWith(text, searchString)
```

**Variant**

```excel
$json.filename.endsWith('.pdf')
```

ตรวจสอบว่าไฟล์เป็นนามสกุล PDF

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | string |  | ข้อความที่ต้องการตรวจสอบ |
| searchString | Yes | string |  | ข้อความท้ายสุดที่ต้องการค้นหา |

## เคสการใช้งาน

### ตรวจสอบนามสกุลไฟล์

ตรวจสอบว่าไฟล์เป็นนามสกุล .pdf, .docx หรือ .xlsx

_เหมาะกับ:_ file-type-validation

### ตรวจสอบท้ายสุด URL

ตรวจสอบว่า URL ลงท้ายด้วย /api หรือ /webhook

_เหมาะกับ:_ url-endpoint-check

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ตรวจสอบนามสกุล

```excel
{{ endsWith('document.pdf', '.pdf') }}
```

**ผลลัพธ์:** `true`

ไฟล์ 'document.pdf' สิ้นสุดด้วย '.pdf' จึงคืนค่า true

### 2. ตัวอย่างที่ 2: ตรวจสอบประเภทไฟล์

```excel
{{ endsWith($json.filename, '.xlsx') || endsWith($json.filename, '.xls') }}
```

**ผลลัพธ์:** `true`

ตรวจสอบว่าเป็นไฟล์ Excel

### 3. ตัวอย่างที่ 3: ตรวจสอบ Webhook

```excel
{{ $json.url.endsWith('/webhook') }}
```

**ผลลัพธ์:** `true`

ตรวจสอบว่า URL สิ้นสุดด้วย /webhook

## หมายเหตุเพิ่มเติม

⚠️ ฟังก์ชัน endsWith() คำนึงถึง case จึงต้องระวัง ใช้ร่วมกับ toLowerCase() เพื่อไม่สนใจ case หรือ startsWith() เพื่อตรวจสอบหลักสูตร

## คำถามที่พบบ่อย

**Q: endsWith() คำนึงถึง Case sensitivity หรือไม่?**

ใช่ endsWith() คำนึงถึงตัวใหญ่-ตัวเล็ก เพื่อไม่สนใจให้แปลงเป็นตัวเดียวกันก่อน

**Q: endsWith() จะทำงานกับ empty string ได้หรือ?**

ใช่ endsWith() จะคืนค่า true ถ้าค้นหา empty string เพราะทุกสตริงสิ้นสุดด้วย empty string

**Q: ใช้ endsWith() เมื่อไหร่ในการทำงาน?**

ใช้เมื่อต้องการตรวจสอบนามสกุลไฟล์ ส่วนท้ายข้อความ หรือรูปแบบท้ายสุด

## ฟังก์ชันที่เกี่ยวข้อง

- starts-with-n8n
- [includes – ฟังก์ชันตรวจสอบว่าอาร์เรย์มีค่าใดค่าหนึ่งหรือไม่](https://www.thepexcel.com/functions/n8n/string-functions/includes-n8n/)
- last-index-of-n8n

---

_Source: [https://www.thepexcel.com/functions/n8n/string-functions/ends-with-n8n/](https://www.thepexcel.com/functions/n8n/string-functions/ends-with-n8n/)_
