---
title: includes – ฟังก์ชันตรวจสอบว่าอาร์เรย์มีค่าใดค่าหนึ่งหรือไม่
url: https://www.thepexcel.com/functions/n8n/string-functions/includes-n8n/
type: function-explainer
program: n8n
syntax: "includes(array, value)"
date: 2025-12-16
updated: 2025-12-17
scores:
  popularity: 8
  difficulty: 2
  usefulness: 8
---

# includes – ฟังก์ชันตรวจสอบว่าอาร์เรย์มีค่าใดค่าหนึ่งหรือไม่

> ตรวจสอบว่าอาร์เรย์มีค่าที่กำหนดหรือไม่

## คำอธิบาย

includes ตรวจสอบการมีอยู่ของค่าในอาร์เรย์ คืนค่า true หากพบค่าที่ระบุ ใช้มากในการตรวจสอบความถูกต้องของข้อมูล เช่นตรวจสอบว่า status มีค่า 'completed' หรือตรวจสอบว่า ID อยู่ในรายชื่อ

## Syntax

```excel
includes(array, value)
```

**Variant**

```excel
$json.statuses.includes('active')
```

ใช้เป็น method เมื่อ $json.statuses เป็น array

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| array | Yes | array |  | Array ที่ต้องการตรวจสอบ |
| value | Yes | any |  | ค่าที่ต้องการค้นหา (เช่น 'active', 123, true) |

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

### ตรวจสอบสถานะ

ตรวจสอบว่า status ของข้อมูลอยู่ในรายชื่อ status ที่เป็นที่ยอมรับ เช่น ['active', 'completed']

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

### ตรวจสอบสิทธิ์

ตรวจสอบว่าผู้ใช้มีสิทธิ์เข้าถึง โดยตรวจสอบว่า role อยู่ในรายชื่อ allowed roles

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

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ตรวจสอบค่าพื้นฐาน

```excel
{{ includes(['apple', 'banana', 'orange'], 'banana') }}
```

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

ฟังก์ชันตรวจสอบว่า 'banana' อยู่ในอาร์เรย์หรือไม่ ผลลัพธ์คือ true

### 2. ตัวอย่างที่ 2: ตรวจสอบสถานะ

```excel
{{ includes(['pending', 'active', 'completed'], $json.status) }}
```

**ผลลัพธ์:** `true หรือ false`

สูตรนี้ตรวจสอบว่า status ของข้อมูลอยู่ในรายชื่อสถานะที่ยอมรับหรือไม่

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

```excel
{{ includes($node['Get Roles'].json.data, $json.userRole) ? 'Allow' : 'Deny' }}
```

**ผลลัพธ์:** `Allow หรือ Deny`

ตรวจสอบว่า userRole มีสิทธิ์โดยตรวจสอบในรายชื่อ roles ที่อนุญาต

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

⚠️ ฟังก์ชัน includes() ตรวจสอบ strict equality (===) หากต้องการตรวจสอบแบบอื่น ให้ใช้ some() หรือ find() ตรวจสอบ case-sensitive เมื่อเปรียบเทียบ string

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

**Q: includes() ตรวจสอบ case-sensitive หรือไม่?**

ใช่ includes() ตรวจสอบ case-sensitive ดังนั้น 'Apple' ไม่เท่ากับ 'apple' หากต้องการ case-insensitive ให้ใช้ map + toLowerCase()

**Q: includes() จะรับ object ได้หรือ?**

ได้ แต่จะตรวจสอบ reference ไม่ใช่ค่า ถ้าต้องการตรวจสอบ object ด้วยค่า ให้ใช้ some() หรือ find()

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

ใช้เมื่อต้องการตรวจสอบว่าค่าใดค่าหนึ่งอยู่ในรายชื่อ เช่นตรวจสอบสถานะ สิทธิ์ หมวดหมู่ เป็นต้น

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

- [some – ตรวจสอบว่ามีรายการใดผ่านเงื่อนไขหรือไม่](https://www.thepexcel.com/functions/n8n/array-functions/some-n8n/)
- find-n8n
- [filter – กรองรายการจากอาร์เรย์ตามเงื่อนไข](https://www.thepexcel.com/functions/n8n/array-functions/filter-n8n/)

---

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