此函数获取数组维度的长度(条目数)。
您提供数组索引值,该函数将返回一个整数值,表示数组包含的条目数。此函数也可用于多维数组,只要您在提供数组索引时指定要获取哪个维度的长度即可,遵循以下模式:
// Returns the first dimension of the array
val = array_length(my_array);
// Returns the second dimension of the array
val = array_length(my_array[0]);
// Returns the third dimension of the array
val = array_length(my_array[0][0]);
// etc.
注意如果传递给函数的数据类型不是数组,则该函数将返回 0。
array_length(array_index);
参数 | 类型 | 描述 |
---|---|---|
array_index | Array | The array to check. |
for (var i = 0; i < array_length(a); ++i)
{
a[i] = -1;
}
上面的代码将循环遍历一个数组,并将每个条目设置为-1。