跳至主要内容

切片节点

Slice Node Screenshot

概述

Slice节点用于提取数组的一部分。它接收一个数组作为输入,并输出一个新的数组,该数组从指定的索引开始并包含指定数量的元素。

该节点对于操作数组非常有用,例如从更大的数据集中提取子集数据。

输入项

标题数据类型描述默认值备注
Inputany[]The array to be sliced.(required)The input will be coerced into an array if it is not an array.
StartnumberThe index at which to start the slice.0The input will be coerced into a number if it is not a number.
CountnumberThe number of elements to include in the slice. If not provided, all elements will be included.(all)The input will be coerced into a number if it is not a number. This input is optional.

示例1:切片数组

  1. 创建一个Array Node并将值设置为[1, 2, 3, 4, 5]
  2. 创建一个 Slice 节点,将 Start 设置为 2,将 Count 设置为 2
  3. 将Array节点连接到Slice节点的Input
  4. 运行图表。Slice节点的Output输出应为[3, 4]

Slice Node Example 1

错误处理

如果未提供Input或其不是数组,Slice节点将报错。如果StartCount不是数字,也会报错。

常见问题

问:如果Start大于数组长度会发生什么?

A: Slice节点将返回一个空数组。

问:如果Count大于数组中的元素数量会发生什么?

A: Slice节点将返回从Start到数组末尾的所有元素。

问:我可以在StartCount中使用负数吗?

A: 是的,您可以使用负数作为Start参数来从数组末尾开始计数。但是,如果对Count参数使用负数将会导致错误。

另请参阅