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移除 false 值
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-要壓縮的陣列組

Output:

FieldTypeDescription
resultarray缺少元素的值
lengthnumber壓縮後的陣列

Released under the Apache 2.0 License.