Skip to content

Array Operations

List manipulation — chunk, flatten, group, map, reduce, zip, and more.

12 modules

ModuleDescription
แบ่งอาเรย์แบ่งอาร์เรย์เป็นชิ้นตามขนาดที่กำหนด
บีบอัดลบค่า null/ว่างเปล่าออกจากอาเรย์
ความแตกต่างของอาเรย์หาองค์ประกอบในอาร์เรย์แรกที่ไม่อยู่ในอื่น ๆ
ลบลบ N องค์ประกอบแรกจากอาเรย์
แบนอาเรย์ทำให้อาร์เรย์ซ้อนเป็นอาร์เรย์เดียว
จัดกลุ่มตามจัดกลุ่มองค์ประกอบอาเรย์ตามคีย์
จุดตัดของอาเรย์หาองค์ประกอบที่เหมือนกันระหว่างอาร์เรย์
รวมอาเรย์รวมองค์ประกอบอาร์เรย์เป็นสตริง
แมปอาเรย์แปลงแต่ละองค์ประกอบในอาร์เรย์
ลดอาเรย์ลดอาร์เรย์เป็นค่าเดียว
นำนำ N องค์ประกอบแรกจากอาเรย์
ซิปอาเรย์รวมอาเรย์หลายอันตามลำดับ

Modules

แบ่งอาเรย์

array.chunk

แบ่งอาร์เรย์เป็นชิ้นตามขนาดที่กำหนด

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
sizenumberYes10Number of items per chunk

Output:

FieldTypeDescription
resultarrayอาร์เรย์ของชิ้น
chunksnumberอาร์เรย์ของชิ้น

Example: Chunk into groups of 3

yaml
array: [1, 2, 3, 4, 5, 6, 7, 8, 9]
size: 3

Example: Batch process items

yaml
array: ["a", "b", "c", "d", "e"]
size: 2

บีบอัด

array.compact

ลบค่า null/ว่างเปล่าออกจากอาเรย์

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-อาเรย์ที่ต้องการบีบอัด
remove_empty_stringsbooleanNoTrueลบสตริงที่ว่างเปล่า
remove_zerobooleanNoFalseลบสตริงที่ว่างเปล่า
remove_falsebooleanNoFalseลบค่าที่เป็นศูนย์

Output:

FieldTypeDescription
resultarrayลบค่าที่เป็นเท็จ
removednumberอาเรย์ที่บีบอัดแล้ว

ความแตกต่างของอาเรย์

array.difference

หาองค์ประกอบในอาร์เรย์แรกที่ไม่อยู่ในอื่น ๆ

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
subtractarrayYes-Arrays containing items to remove from the base array

Output:

FieldTypeDescription
resultarrayองค์ประกอบเฉพาะในอาร์เรย์แรก
lengthnumberองค์ประกอบเฉพาะในอาร์เรย์แรก

Example: Find unique elements

yaml
array: [1, 2, 3, 4, 5]
subtract: [[2, 4], [5]]

ลบ

array.drop

ลบ N องค์ประกอบแรกจากอาเรย์

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-อาเรย์ต้นทาง
countnumberYes1อาเรย์ต้นทาง

Output:

FieldTypeDescription
resultarrayจำนวนองค์ประกอบที่จะลบ
droppednumberองค์ประกอบที่เหลือ

แบนอาเรย์

array.flatten

ทำให้อาร์เรย์ซ้อนเป็นอาร์เรย์เดียว

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
depthnumberNo1How many levels of nesting to flatten (-1 for infinite)

Output:

FieldTypeDescription
resultarrayอาร์เรย์ที่ทำให้แบนแล้ว
lengthnumberอาร์เรย์ที่ทำให้แบนแล้ว

Example: Flatten one level

yaml
array: [[1, 2], [3, 4], [5, 6]]
depth: 1

Example: Flatten all levels

yaml
array: [[1, [2, [3, [4]]]]]
depth: -1

จัดกลุ่มตาม

array.group_by

จัดกลุ่มองค์ประกอบอาเรย์ตามคีย์

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-อาเรย์ของออบเจ็กต์ที่ต้องการจัดกลุ่ม
keystringYes-อาเรย์ของออบเจ็กต์ที่ต้องการจัดกลุ่ม

Output:

FieldTypeDescription
groupsobjectชื่อคุณสมบัติที่ใช้จัดกลุ่ม
keysarrayผลลัพธ์ที่จัดกลุ่มแล้ว
countnumberผลลัพธ์ที่จัดกลุ่มแล้ว

จุดตัดของอาเรย์

array.intersection

หาองค์ประกอบที่เหมือนกันระหว่างอาร์เรย์

Parameters:

NameTypeRequiredDefaultDescription
arraysarrayYes-Array of arrays to process (for intersection, union)

Output:

FieldTypeDescription
resultarrayองค์ประกอบที่เหมือนกัน
lengthnumberองค์ประกอบที่เหมือนกัน

Example: Find common elements

yaml
arrays: [[1, 2, 3, 4], [2, 3, 5], [2, 3, 6]]

รวมอาเรย์

array.join

รวมองค์ประกอบอาร์เรย์เป็นสตริง

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
separatorselect (, , ,, , `
, , - `, ``)No,String to insert between items when joining

Output:

FieldTypeDescription
resultstringสตริงที่รวมแล้ว

Example: Join with comma

yaml
array: ["apple", "banana", "cherry"]
separator: ,

Example: Join with newline

yaml
array: ["Line 1", "Line 2", "Line 3"]
separator:

แมปอาเรย์

array.map

แปลงแต่ละองค์ประกอบในอาร์เรย์

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
operationselect (multiply, add, subtract, divide, extract, uppercase, lowercase, trim, tostring, tonumber)Yes-Transformation to apply to each item
valueanyNo-Value for the operation: number for math operations, field name for extract

Output:

FieldTypeDescription
resultarrayอาร์เรย์ที่แปลงแล้ว
lengthnumberอาร์เรย์ที่แปลงแล้ว

Example: Multiply numbers

yaml
array: [1, 2, 3, 4, 5]
operation: multiply
value: 2

Example: Extract field from objects

yaml
array: [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
operation: extract
value: name

ลดอาเรย์

array.reduce

ลดอาร์เรย์เป็นค่าเดียว

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-Array of items to process. Can be numbers, strings, or objects.
operationselect (sum, product, average, min, max, count, join, first, last)Yes-How to combine all items into a single value
separatorselect (, , ,, , `
, , - `, ``)No,String to insert between items when joining

Output:

FieldTypeDescription
resultanyค่าที่ลดแล้ว
operationstringค่าที่ลดแล้ว

Example: Sum numbers

yaml
array: [1, 2, 3, 4, 5]
operation: sum

Example: Join strings

yaml
array: ["Hello", "World", "from", "Flyto"]
operation: join
separator:

นำ

array.take

นำ N องค์ประกอบแรกจากอาเรย์

Parameters:

NameTypeRequiredDefaultDescription
arrayarrayYes-อาเรย์ต้นทาง
countnumberYes1อาเรย์ต้นทาง

Output:

FieldTypeDescription
resultarrayจำนวนองค์ประกอบที่จะนำ
lengthnumberองค์ประกอบที่นำมา

ซิปอาเรย์

array.zip

รวมอาเรย์หลายอันตามลำดับ

Parameters:

NameTypeRequiredDefaultDescription
arraysarrayYes-อาเรย์ของอาเรย์ที่ต้องการซิป
fill_valueanyNo-อาเรย์ของอาเรย์ที่ต้องการ zip

Output:

FieldTypeDescription
resultarrayค่าเมื่อองค์ประกอบหายไป
lengthnumberอาเรย์ที่ซิปแล้ว

Released under the Apache 2.0 License.