---
title: some – ตรวจสอบว่ามีรายการใดผ่านเงื่อนไขหรือไม่
url: https://www.thepexcel.com/functions/n8n/array-functions/some-n8n/
type: function-explainer
program: n8n
syntax: array.some(callback)
date: 2025-12-16
updated: 2025-12-23
scores:
  popularity: 6
  difficulty: 4
  usefulness: 6
---

# some – ตรวจสอบว่ามีรายการใดผ่านเงื่อนไขหรือไม่

> some() เป็น JavaScript array method ที่ใช้ตรวจสอบว่ามีรายการอย่างน้อยหนึ่งรายการในอาร์เรย์ผ่านเงื่อน

## คำอธิบาย

some() เป็น JavaScript array method ที่ใช้ตรวจสอบว่ามีรายการอย่างน้อยหนึ่งรายการในอาร์เรย์ผ่านเงื่อนไขที่กำหนดหรือไม่ โดยคืนค่า true ทันทีเมื่อเจอรายการแรกที่ผ่านเงื่อนไข และคืนค่า false ถ้าไม่มีรายการใดผ่านเลย ใช้บ่อยใน n8n workflow

## Syntax

```excel
array.some(callback)
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| callback | Yes | Function (Arrow function) |  | ฟังก์ชันที่ทดสอบแต่ละรายการ รับ parameters: (element, index, array) และคืนค่า truthy/falsy เพื่อบ่งบอกว่ารายการนั้นผ่านเงื่อนไขหรือไม่ |
| element | No | Any |  | รายการปัจจุบันที่กำลังประมวลผล (parameter แรกของ callback) |
| index | No | Number |  | ตำแหน่ง index ของรายการปัจจุบัน (parameter ที่สองของ callback, ใช้ไม่บังคับ) |
| array | No | Array |  | Array ต้นฉบับที่เรียกใช้ some() (parameter ที่สามของ callback, ใช้ไม่บังคับ) |

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

### Scenario 1

General usage

_เหมาะกับ:_ general

## ตัวอย่าง

### 1. ตัวอย่างพื้นฐาน - เช็คว่ามีตัวเลขมากกว่า 10

```excel
{{ $json.numbers.some(x => x > 10) }}
```

**ผลลัพธ์:** `true (ถ้ามีตัวเลขใดมากกว่า 10) หรือ false (ถ้าไม่มี)`

สมมติว่า $json.numbers = [2, 5, 8, 1, 4]
ผลลัพธ์: false (ไม่มีตัวเลขใดมากกว่า 10)

แต่ถ้า $json.numbers = [2, 5, 15, 1, 4]
ผลลัพธ์: true (มี 15 ที่มากกว่า 10)

ใช้ใน IF node เพื่อแยก workflow ตามสภาพข้อมูล

### 2. เช็คว่ามี admin ในรายชื่อผู้ใช้

```excel
{{ $json.users.some(user => user.role === 'admin') }}
```

**ผลลัพธ์:** `true (ถ้ามีผู้ใช้ที่เป็น admin อย่างน้อยหนึ่งคน)`

สมมติว่า $json.users = [
  { name: 'John', role: 'user' },
  { name: 'Sarah', role: 'admin' },
  { name: 'Mike', role: 'user' }
]
ผลลัพธ์: true (เพราะ Sarah เป็น admin)

ใช้ใน IF node: ถ้ามี admin ให้ส่ง notification ไป Slack แต่ถ้าไม่มีให้ข้าม

### 3. เช็คว่ามีสินค้าที่ราคาเกิน 1000 บาท

```excel
{{ $json.items.some(item => item.price > 1000) }}
```

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

สมมติว่า $json.items = [
  { name: 'Keyboard', price: 500 },
  { name: 'Monitor', price: 3500 },
  { name: 'Mouse', price: 250 }
]
ผลลัพธ์: true (เพราะ Monitor ราคา 3500)

ใช้ Set node สร้างฟิลด์:
has_expensive_items: {{ $json.items.some(item => item.price > 1000) }}

จากนั้นใช้ IF node เช็ค has_expensive_items เพื่อใช้ส่วนลดพิเศษ

### 4. เช็คว่ามี email ที่ invalid

```excel
{{ $json.contacts.some(contact => !contact.email.isEmail()) }}
```

**ผลลัพธ์:** `true (ถ้ามี contact ที่ email ไม่ถูกต้อง)`

สมมติว่า $json.contacts = [
  { name: 'Alice', email: 'alice@example.com' },
  { name: 'Bob', email: 'invalid-email' },
  { name: 'Charlie', email: 'charlie@test.com' }
]
ผลลัพธ์: true (เพราะ Bob มี email ที่ไม่ถูกต้อง)

ใช้ใน IF node: ถ้ามี invalid email ให้ส่งไป error handling workflow

### 5. เช็คว่ามี order ที่ status เป็น pending

```excel
{{ $json.orders.some(order => order.status === 'pending') }}
```

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

สมมติว่า $json.orders = [
  { id: 1, status: 'completed' },
  { id: 2, status: 'pending' },
  { id: 3, status: 'shipped' }
]
ผลลัพธ์: true (เพราะ order id 2 เป็น pending)

ใช้ใน Code node:
if ($input.all().some(item => item.json.orders.some(order => order.status === 'pending'))) {
  // ส่ง notification
}

เทคนิค: nested some() เพื่อเช็ค multiple levels

### 6. เช็คว่ามีคำใน array ที่ขึ้นต้นด้วย 'error'

```excel
{{ $json.logs.some(log => log.startsWith('error')) }}
```

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

สมมติว่า $json.logs = [
  'info: Server started',
  'warning: High memory usage',
  'error: Connection failed'
]
ผลลัพธ์: true (เพราะมี 'error: Connection failed')

ใช้ใน IF node เพื่อแยก error logs ออกจาก normal logs

### 7. เช็คว่ามีตัวเลขคู่ใน array

```excel
{{ $json.numbers.some(num => num % 2 === 0) }}
```

**ผลลัพธ์:** `true (ถ้ามีตัวเลขคู่อย่างน้อยหนึ่งตัว)`

สมมติว่า $json.numbers = [1, 3, 5, 8, 9]
ผลลัพธ์: true (เพราะมี 8 ที่เป็นเลขคู่)

ใช้ใน Set node:
has_even_number: {{ $json.numbers.some(num => num % 2 === 0) }}

### 8. เช็คว่ามี property ที่เป็น null หรือ undefined

```excel
{{ $json.data.some(item => item.value == null) }}
```

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

สมมติว่า $json.data = [
  { id: 1, value: 100 },
  { id: 2, value: null },
  { id: 3, value: 200 }
]
ผลลัพธ์: true (เพราะ id 2 มี value เป็น null)

หมายเหตุ: ใช้ == null (double equals) จะเช็คทั้ง null และ undefined พร้อมกัน

ใช้ใน IF node: ถ้ามี null value ให้ clean ข้อมูลก่อนส่งต่อ

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

- some() หยุดทันทีที่เจอรายการแรกที่ผ่าน (short-circuit) ประหยดเวลามากกว่า filter().length > 0

- ใช้ some() ใน IF node เพื่อแยก workflow ตามสภาพข้อมูล เช็ค "มีบ้างหรือไม่"

- some() ไม่เปลี่ยนแปลง array ต้นฉบับ (non-mutating) ปลอดภัยใช้กับข้อมูล $json

- ถ้า array ว่าง some() คืนค่า false เสมอ ควรเช็ค .length > 0 ก่อนใช้ถ้าจำเป็น

- ใช้ arrow function สั้น ๆ เช่น x => x > 10 แทน function(x) { return x > 10 } อ่านง่ายกว่า

- some() เหมาะกับการ validation ข้อมูลก่อนส่งต่อ เช่น เช็คว่ามี invalid email, null value, หรือ error status

- ใช้ร่วมกับ string methods ได้ เช่น .some(item => item.email.isEmail()) เพื่อเช็คความถูกต้อง

- ใช้ == null (double equals) แทน === null เพื่อเช็คทั้ง null และ undefined พร้อมกัน

- nested some() ใช้กับ array หลายชั้นได้ แต่ถ้าซับซ้อนมากควรใช้ Code node แทน

- some() ไม่รองรับ async callback ถ้าต้องการ async ให้ใช้ Promise.all() ใน Code node

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

**Q: some() ต่างจาก every() อย่างไร?**

some() คืนค่า true ถ้ามีรายการใด ๆ ผ่านเงื่อนไข (อย่างน้อยหนึ่งรายการ) ในขณะที่ every() คืนค่า true ต้องทุกรายการผ่านเงื่อนไข

ตัวอย่าง:
[2, 5, 8].some(x => x > 5)  // true (มี 8 ที่มากกว่า 5)
[2, 5, 8].every(x => x > 5) // false (ไม่ใช่ทุกตัวมากกว่า 5)

ใช้ some() เมื่อต้องการ "มีบ้างหรือไม่"
ใช้ every() เมื่อต้องการ "ทุกอันต้องผ่าน"

**Q: some() ต่างจาก filter().length > 0 อย่างไร?**

some() มีประสิทธิภาพดีกว่าเพราะหยุดทันทีที่เจอรายการแรกที่ผ่าน (short-circuit) ในขณะที่ filter() จะวนลูปทั้ง array เสมอ

ตัวอย่าง array ขนาด 1,000 รายการ:
- some(x => x > 10): หยุดที่รายการที่ 5 (เจอแล้ว) → เร็วมาก
- filter(x => x > 10).length > 0: วนลูปครบ 1,000 รายการ → ช้ากว่า

ใช้ some() สำหรับเช็คว่า "มีหรือไม่"
ใช้ filter() เมื่อต้องการ array ที่กรองแล้ว

**Q: some() ใช้ได้ใน n8n node ไหนบ้าง?**

some() ใช้ได้ในทุก node ที่รองรับ expressions:

1. IF node: {{ $json.items.some(x => x.status === 'error') }}
   ลำทาง workflow ตามสภาพข้อมูล

2. Set node: 
   has_errors: {{ $json.logs.some(log => log.level === 'error') }}
   สร้างฟิลด์ boolean

3. Code node:
   if ($input.all().some(item => item.json.price > 1000)) { ... }
   Logic ที่ซับซ้อน

4. Switch node: ใช้ some() ใน routing rules

แต่ละ node เหมาะกับงานต่างกัน ขึ้นอยู่กับความซับซ้อนของ logic

**Q: ถ้า array ว่าง some() จะคืนค่าอะไร?**

some() จะคืนค่า false เสมอถ้า array ว่าง เพราะไม่มีรายการใดให้ทดสอบ

ตัวอย่าง:
{{ [].some(x => x > 10) }}
ผลลัพธ์: false

นี่คือ behavior มาตรฐานของ JavaScript และสอดคล้องกับตรรกศาสตร์ว่า "ในชุดว่าง ไม่มีรายการใดผ่านเงื่อนไข"

ควรเช็คว่า array มีข้อมูลก่อนใช้ some():
{{ $json.items?.length > 0 && $json.items.some(x => x.valid) }}

**Q: some() รองรับ async callback ไหม?**

some() ใน JavaScript มาตรฐานไม่รองรับ async callback โดยตรง ถ้าใช้ async function จะได้ Promise ซึ่ง some() จะถือว่า truthy เสมอ

ถ้าต้องการ async operation ให้ใช้ใน Code node แทน:

const results = await Promise.all(
  $input.all().map(item => checkAPI(item.json))
);
return results.some(result => result.valid);

หรือใช้ HTTP Request node กับ Split In Batches เพื่อทำ async ทีละ batch

**Q: ใช้ some() กับ nested array ได้ไหม?**

ได้ครับ ใช้ nested some() เพื่อเช็ค array หลายชั้น

ตัวอย่าง:
{{ $json.departments.some(dept => 
     dept.employees.some(emp => emp.salary > 100000)
   ) }}

อธิบาย: เช็คว่ามี department ใดที่มี employee ที่เงินเดือนเกิน 100,000

แต่ถ้า logic ซับซ้อนมาก แนะนำใช้ Code node เพื่อความอ่านง่าย:

const hasHighSalary = $input.all().some(item => 
  item.json.departments.some(dept => 
    dept.employees.some(emp => emp.salary > 100000)
  )
);
return { hasHighSalary };

## แหล่งข้อมูลเพิ่มเติม

- [n8n Docs: Data transformation functions - Arrays](https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/) _(article)_
- [MDN Web Docs: Array.prototype.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some) _(article)_
- [n8n Community: Array Methods Examples](https://community.n8n.io) _(article)_

---

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