跳转至

数组#

参考文档,列出了支持表达式中数组数据转换的内置便利函数。

表达式中的JavaScript

你可以在表达式中使用任何JavaScript。更多信息请参阅表达式

average(): Number #

Returns the value of elements in an array

chunk(size: Number): Array #

Splits arrays into chunks with a length of size

Function parameters#

sizeRequiredNumber

The size of each chunk.


compact(): Array #

Removes empty values from the array.

difference(arr: Array): Array #

Compares two arrays. Returns all elements in the base array that aren't present in arr.

Function parameters#

arrRequiredArray

The array to compare to the base array.


intersection(arr: Array): Array #

Compares two arrays. Returns all elements in the base array that are present in arr.

Function parameters#

arrRequiredArray

The array to compare to the base array.


first(): Array item #

Returns the first element of the array.

isEmpty(): Boolean #

Checks if the array doesn't have any elements.

isNotEmpty(): Boolean #

Checks if the array has elements.

last(): Array item #

Returns the last element of the array.

max(): Number #

Returns the highest value in an array.

merge(arr: Array): Array #

Merges two Object-arrays into one array by merging the key-value pairs of each element.

Function parameters#

arrRequiredArray

The array to merge into the base array.


min(): Number #

Gets the minimum value from a number-only array.

pluck(fieldName?: String): Array #

Returns an array of Objects where keys equal the given field names.

Function parameters#

fieldNameOptionalString

The key(s) you want to retrieve. You can enter as many keys as you want, as comma-separated strings.


randomItem(): Array item #

Returns a random element from an array.

removeDuplicates(key?: String): Array #

Removes duplicates from an array.

Function parameters#

keyOptionalString

A key, or comma-separated list of keys, to check for duplicates.


renameKeys(from: String, to: String): Array #

Renames all matching keys in the array. You can rename more than one key by entering a series of comma separated strings, in the pattern oldKeyName, newKeyName.

Function parameters#

fromRequiredString

The key you want to rename.

toRequiredString

The new name.


smartJoin(keyField: String, nameField: String): Array #

Operates on an array of objects where each object contains key-value pairs. Creates a new object containing key-value pairs, where the key is the value of the first pair, and the value is the value of the second pair. Removes non-matching and empty values and trims any whitespace before joining.

Function parameters#

keyFieldRequiredString

The key to join.

nameFieldRequiredString

The value to join.

Example

Basic usage
1
2
3
4
// 输入
{{ [{"type":"fruit", "name":"apple"},{"type":"vegetable", "name":"carrot"} ].smartJoin("type","name") }}
// 输出
[Object: {"fruit":"apple","vegetable":"carrot"}]

sum(): Number #

Returns the total sum all the values in an array of parsable numbers.

toJsonString(): String #

Convert an array to a JSON string. Equivalent of JSON.stringify.

union(arr: Array): Array #

Concatenates two arrays and then removes duplicate.

Function parameters#

arrRequiredArray

The array to compare to the base array.


unique(key?: String): Array #

Remove duplicates from an array.

Function parameters#

keyOptionalString

A key, or comma-separated list of keys, to check for duplicates.


此页面是否
💬 微信

🚀 与作者交流

关注公众号
n8n实战笔记公众号
n8n实战笔记
📚 教程 💡 案例 🔧 技巧
添加微信
添加作者微信
1对1 专业指导
⚡ 快答 🎯 定制 🚀 支持