Skip to content

Object#

Object.compact()#

Description: 移除所有值为空的字段,即值为 null"" 的字段

Syntax: Object.compact()

Returns: Object

Source: Custom n8n functionality

Examples:

1
2
// obj = {'x':null, 'y':2, 'z':''}
obj.compact() //=> {'y':2}

Object.hasField()#

Description: 如果存在名为 name 的字段,则返回 true。仅检查顶层键。比较区分大小写。

Syntax: Object.hasField(name)

Returns: Boolean

Source: Custom n8n functionality

Parameters:

  • name (String) - 要搜索的键名

Examples:

1
2
// obj = {'name':'Nathan', 'age':42}
obj.hasField('name') //=> true
1
2
3
// obj = {'name':'Nathan', 'age':42}
obj.hasField('Name') //=> false
obj.hasField('inventedField') //=> false

Object.isEmpty()#

Description: 如果 Object 没有设置任何键(字段)或为 null,则返回 true

Syntax: Object.isEmpty()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name': 'Nathan'}
obj.isEmpty() //=> false
1
2
// obj = {}
obj.isEmpty() //=> true

Object.isNotEmpty()#

Description: 如果 Object 至少设置了一个键(字段),则返回 true

Syntax: Object.isNotEmpty()

Returns: Boolean

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name': 'Nathan'}
obj.isNotEmpty() //=> true
1
2
// obj = {}
obj.isNotEmpty() //=> false

Object.keepFieldsContaining()#

Description: 移除值未至少部分匹配给定 value 的所有字段。比较区分大小写。非字符串类型的字段将始终被移除。

Syntax: Object.keepFieldsContaining(value)

Returns: Object

Source: Custom n8n functionality

Parameters:

  • value (String) - 值必须包含的文本才能被保留

Examples:

1
2
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42 }
obj.keepFieldsContaining('Nathan') //=> {'name': 'Mr Nathan'}
1
2
3
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42 }
obj.keepFieldsContaining('nathan') //=> {}
obj.keepFieldsContaining('han') //=> {'name': 'Mr Nathan', 'city':'hanoi'}

Object.keys()#

Description: 返回包含 Object 所有字段名(键)的数组。与 JavaScript 的 Object.keys(obj) 相同。

Syntax: Object.keys()

Returns: Array

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name': 'Mr Nathan', age: 42 }
obj.keys() //=> ['name', 'age']

Object.merge()#

Description: 将两个 Object 合并为一个。如果某个键(字段名)同时存在于两个 Object 中,则使用第一个(基础)Object 的值。

Syntax: Object.merge(otherObject)

Returns: Object

Source: Custom n8n functionality

Parameters:

  • otherObject (Object) - 要与基础 Object 合并的对象。

Examples:

1
2
3
// obj1 = {'name':'Nathan', 'age': 42}
// obj2 = {'name':'Jan', 'city': 'hanoi'}
obj1.merge(obj2) //=> {'name':'Jan', 'city': 'hanoi', 'age':42}

Object.removeField()#

Description: 从 Object 中移除一个字段。与 JavaScript 的 delete 相同。

Syntax: Object.removeField(key)

Returns: Object

Source: Custom n8n functionality

Parameters:

  • key (String) - 要移除的字段名

Examples:

1
2
// obj = {'name':'Nathan', 'city':'hanoi'}
obj.removeField('name') //=> {'city':'hanoi'}

Object.removeFieldsContaining()#

Description: 移除值至少部分匹配给定 value 的键(字段)。比较区分大小写。非字符串类型的字段始终被保留。

Syntax: Object.removeFieldsContaining(value)

Returns: Object

Source: Custom n8n functionality

Parameters:

  • value (String) - 值必须包含的文本才会被移除

Examples:

1
2
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42}
obj.removeFieldsContaining('Nathan') //=> {'city':'hanoi', age: 42}
1
2
3
// obj = {'name': 'Mr Nathan', 'city':'hanoi', age: 42}
obj.removeFieldsContaining('han') //=> {age: 42}
obj.removeFieldsContaining('nathan') //=> {'name': 'Mr Nathan', 'city':'hanoi', age: 42}

Object.toJsonString()#

Description: 将 Object 转换为 JSON 字符串。类似于 JavaScript 的 JSON.stringify()

Syntax: Object.toJsonString()

Returns: String

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name':'Nathan', age:42}
obj.toJsonString() //=> '{"name":"Nathan","age":42}'

Object.urlEncode()#

Description: 从 Object 的键和值生成 URL 参数字符串。仅支持顶层键。

Syntax: Object.urlEncode()

Returns: String

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name':'Mr Nathan', 'city':'hanoi'}
obj.urlEncode() //=> 'name=Mr+Nathan&city=hanoi'

Object.values()#

Description: 返回包含 Object 所有字段值的数组。与 JavaScript 的 Object.values(obj) 相同。

Syntax: Object.values()

Returns: Array

Source: Custom n8n functionality

Examples:

1
2
// obj = {'name': 'Mr Nathan', age: 42 }
obj.values() //=> ['Mr Nathan', 42]