--- title: "数组和对象的表达式" slug: "using-expressions-with-arrays" updated: 2026-10-22T10:00:54Z published: 2026-10-22T10:00:54Z canonical: "support.tulip.co/using-expressions-with-arrays" --- > ## Documentation Index > Fetch the complete documentation index at: https://support.tulip.co/llms.txt > Use this file to discover all available pages before exploring further. # 数组和对象的表达式 *了解在表达式编辑器中处理数组和对象的基础知识。* 了解如何使用表达式处理数组,对于在 Tulip 中处理数据至关重要。您还可以使用表达式将对象分解为不同的数据类型。这使您能够专注于特定数据,从而优化应用程序中的处理流程。 --- ## 涉及数组的表达式 多种类型的表达式执行不同的功能以返回值。这些值可以是单个值,也可以是另一个数组;它们可以是相同的数据类型,也可以是不同的数据类型。 某些表达式使用数组来返回简单的算术值: **array_max()**返回给定数值数组中的最大值。 ![array_max expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_max%20expression.png) **array_min()**返回给定数值数组的最小值。 ![array_min expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_min%20expression.png) **array_avg()**返回给定数值数组的平均值。 ![array_avg expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_avg%20expression.png) ![Array Expressions - Max Min Avg](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array%20Expressions%20-%20Max%20Min%20Avg.gif) 其他表达式使用标准差来返回值。 **array_stdev_population()**返回给定数值数组总体均值的标准差。 ![array_stdev_population expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_stdev_population%20expression.png) **array_stdev_sample()**返回给定数值数组的样本标准差。 ![array_stdev_sample expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_stdev_sample%20expression.png) ![Array Expressions - StDev Pop Samp](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array%20Expressions%20%20-%20StDev%20Pop%20Samp.gif) **array_at_value_index 返回**给定列表中指定索引处的值。如果索引超出范围,则返回 null。 ![array_value_at_index ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_value_at_index%20ex.png) Tulip 平台中使用最广泛的表达式之一是: **array_index_of()**返回给定数组中给定值首次出现的索引。若未找到,则返回“-1”。 ![array_index_of expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/array_index_of%20expression.png) ![Array_Index_Of Ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array_Index_Of%20Ex.png) [正如这篇社区帖子](https://community.tulip.co/t/programmatically-connect-to-serial-devices-with-player-triggers/8133)中所解释的,您可以使用 array_index_of() 来确定串行驱动程序上的 COM 端口。您还可以将其用于[Connector](/r230/docs/connectors)的输出结果,以查找特定的工单。 **LEN()**返回数组中的元素个数。![Len expression ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Len%20expression%20ex.png) 此外,还有一些使用数组来确定给定值的表达式,例如: **arraycontains()**:如果给定值在指定数组中,则返回“true”;否则返回“false”。 ![arraycontains expression yes](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/arraycontains%20expression%20yes.png) ![Array Expressions - Contains](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array%20Expressions%20-%20Contains.gif) 以下表达式使用[正则表达式](https://regex101.com/)来返回数组。您还可以参考[此速查表](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Cheatsheet)来了解正则表达式的功能和语法。 **regex_match()**返回与正则表达式匹配的元素数组。 ![regex_match expression ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/regex_match%20expression%20ex.png) ![regex_match expression ex in app](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/regex_match%20expression%20ex%20in%20app.png) **regex_replace()**返回一个经过修改的数组,其中包含根据表达式定义的字符串替换结果。 ![regex_replace expression ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/regex_replace%20expression%20ex.png) ![regex_replace expression ex in app](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/regex_replace%20expression%20ex%20in%20app.png) 最后,您可以将多个数据类型相似的数组合并,以创建一个新数组。 **array_concat()**将任意数量的同类型数组连接成一个该类型的数组。 ![Array_Concat Expression](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array_Concat%20Expression.png) ![Array_Concat Ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/Array_Concat%20Ex.png) ## 包含对象的表达式 在 Tulip 中,使用对象的表达式都具有相同的功能:从一个对象中收集数据,并将其存储在另一个使用单一数据类型的对象中。以下表达式的工作原理类似,它们使用给定的键(标题)将对象数组转换为基础数组。 **map_to_boolean_list()**根据给定的键,将对象数组转换为布尔数组。![map_to_boolean_list ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/map_to_boolean_list%20ex.png) **map_to_integer_list()**:根据给定的键,将对象数组转换为整型数组。![map_to_integer_list ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/map_to_integer_list%20ex.png) **map_to_number_list()**将对象数组转换为针对给定键的 Number 数组。 ![map_to_number_list ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/map_to_number_list%20ex.png) **map_to_text_list()**将对象数组转换为指定键对应的文本数组。![map_to_text_list ex](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/map_to_text_list%20ex.png) 在下面的示例中,对象数组中的每个对象包含四个数据标题。按钮触发器通过数据操作,将每个键(标题)对应的数据存储到相应的变量数组中(布尔型、数值型等)。 ![map to text ex in app](https://cdn.document360.io/7c6ff534-cad3-4fc8-9583-912c4016362f/Images/Documentation/map%20to%20text%20ex%20in%20app.gif) 结合使用上述 map_to_text 表达式之一与 array_index_of(),可从连接器函数 Output 中提取信息。 **Output** An **output** is the transmission of data from a program to a data set.