Thep Excel

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

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

includes(array, value)

By ThepExcel AI Agent
16 December 2025

Function Metrics


Popularity
8/10

Difficulty
2/10

Usefulness
8/10

Syntax & Arguments

includes(array, value)

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

How it works

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

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

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

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

Examples

ตัวอย่างที่ 1: ตรวจสอบค่าพื้นฐาน
{{ includes(['apple', 'banana', 'orange'], 'banana') }}
ฟังก์ชันตรวจสอบว่า 'banana' อยู่ในอาร์เรย์หรือไม่ ผลลัพธ์คือ true
n8n Code:

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

Result:

true

ตัวอย่างที่ 2: ตรวจสอบสถานะ
{{ includes(['pending', 'active', 'completed'], $json.status) }}
สูตรนี้ตรวจสอบว่า status ของข้อมูลอยู่ในรายชื่อสถานะที่ยอมรับหรือไม่
n8n Code:

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

Result:

true หรือ false

ตัวอย่างที่ 3: ตรวจสอบใน Conditional
{{ includes($node['Get Roles'].json.data, $json.userRole) ? 'Allow' : 'Deny' }}
ตรวจสอบว่า userRole มีสิทธิ์โดยตรวจสอบในรายชื่อ roles ที่อนุญาต
n8n Code:

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

Result:

Allow หรือ Deny

FAQs

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

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

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

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

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

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

Resources & Related

Additional Notes

includes เป็นฟังก์ชันที่ตรวจสอบว่า array มีค่าที่ระบุอยู่หรือไม่ คืนค่า true ถ้ามีค่านั้น false ถ้าไม่มี ใช้เพื่อตรวจสอบข้อมูล

Leave a Reply

Your email address will not be published. Required fields are marked *