# StaticArray
具有固定长度的通用类型的可随机访问的值序列。
¥A randomly accessible sequence of values of a generic type with a fixed length.
StaticArray API 与 数组 API 类似,重要的区别在于它具有无法更改的固定长度。与普通数组不同,StaticArray 没有单独的后备缓冲区,因此没有间接级别,因此可以具有最小的开销和与 C 中的数组非常相似的性能特性。
¥The StaticArray API is similar to the Array API, with the important difference that it has a fixed length that cannot change. Unlike a normal Array, a StaticArray does not have a separate backing buffer, so no level of indirection, and as such can have minimal overhead and performance characteristics very similar to arrays in C.
# 构造函数
¥Constructor
- new StaticArray<T>(length: i32)- 构造一个新的静态数组。 - ¥Constructs a new static array. 
# 静态成员
¥Static members
- function fromArray<T>(source: Array<T>): StaticArray<T>- 从普通数组创建静态数组。 - ¥Creates a static array from a normal array. 
- function concat<T>(source: StaticArray<T>, other: StaticArray<T>): StaticArray<T>- 已弃用!与实例成员 - concat类似,但获取并返回- StaticArray。- ¥***Deprecated!*** Like the instance member - concat, but taking and returning a- StaticArray.- 最好使用参数化 - concat实例方法来代替- StaticArray.concat。- ¥Instead of - StaticArray.concatbetter to use parametric- concatinstance method.
- function slice<T>(source: StaticArray<T>, start?: i32, end?: i32): StaticArray<T>- 已弃用!与实例成员 - slice类似,但返回- StaticArray。- ¥***Deprecated!*** Like the instance member - slice, but returning a- StaticArray.- 最好使用参数化 - slice实例方法来代替- StaticArray.slice。- ¥Instead of - StaticArray.slicebetter to use parametric- sliceinstance method.
# 实例成员
¥Instance members
# 字段
¥Fields
- readonly length: i32- 此静态数组的固定长度。 - ¥The fixed length of this static array. 
# 方法
¥Methods
- function at(pos: i32): T- 获取指定位置的元素。此方法允许正整数和负整数。负整数从最后一个元素开始倒数。 - ¥Gets the element at the specified position. This method allows for positive and negative integers. Negative integers count back from the last element. 
- function concat<U extends ArrayLike<T> = Array<T>>(other: U): U- 按此顺序将此静态数组和另一个普通数组的值连接到一个新的普通数组。参数 - U接受- Array<T>或- StaticArray<T>类型。- ¥Concatenates the values of this static and the other normal array to a new normal array, in this order. Patameter - Uaccepts- Array<T>or- StaticArray<T>types.
- function copyWithin(target: i32, start: i32, end?: i32): this- 将数组值的区域复制到从目标位置开始的相应值上。 - ¥Copies a region of an array's values over the respective values starting at the target location. 
- function every(fn: (value: T, index: i32, self: StaticArray<T>) => bool): bool- 使用数组的每个值调用指定的函数,直到找到函数返回 - false的第一个值。如果所有函数都返回- true或数组为空,则返回- true,否则返回- false。- ¥Calls the specified function with every value of the array until it finds the first value for which the function returns - false. Returns- trueif all functions returned- trueor the array is empty, otherwise- false.
- function fill(value: T, start?: i32, end?: i32): this- 将数组中从 - start(含)到- end(不含)的值替换为指定值,返回该数组。- ¥Replaces the values of the array from - startinclusive to- endexclusive in place with the specified value, returning the array.
- function filter(fn: (value: T, index: i32, self: StaticArray<T>) => bool): Array<T>- 使用数组的每个值调用指定的函数,返回一个新数组,其中包含函数返回 - true的所有值。- ¥Calls the specified function with every value of the array, returning a new array with all values for which the function returned - true.
- function findIndex(fn: (value: T, index: i32, self: StaticArray<T>) => bool): i32- 使用数组的每个值调用指定的函数,直到找到该函数返回 - true的第一个值,并返回其索引。如果情况并非如此,则返回- -1。- ¥Calls the specified function with every value of the array until it finds the first value for which the function returns - true, returning its index. Returns- -1if that's never the case.
- function findLastIndex(fn: (value: T, index: i32, self: StaticArray<T>) => bool): i32;- 使用从末尾开始的数组的每个值调用指定的函数,直到找到该函数返回 - true的第一个值,并返回其索引。如果情况并非如此,则返回- -1。- ¥Calls the specified function with every value of the array starting at the end until it finds the first value for which the function returns - true, returning its index. Returns- -1if that's never the case.
- function forEach(fn: (value: T, index: i32, self: StaticArray<T>) => void): void- 使用数组的每个值调用指定的函数。 - ¥Calls the specified function with every value of the array. 
- function includes(value: T, fromIndex?: i32): bool- 测试数组是否包含指定值,可以选择提供起始索引。 - ¥Tests if the array includes the specified value, optionally providing a starting index. 
- function indexOf(value: T, fromIndex?: i32): i32- 获取可以在数组中找到指定值的第一个索引。如果未找到则返回 - -1。- ¥Gets the first index where the specified value can be found in the array. Returns - -1if not found.
- function join(separator?: string): string- 将数组的所有值连接到一个字符串,并用指定的分隔符分隔(默认值: - ,)。- ¥Concatenates all values of the array to a string, separated by the specified separator (default: - ,).
- function lastIndexOf(value: T, fromIndex?: i32): i32- 获取可以在数组中找到指定值的最后一个索引。如果未找到则返回 - -1。- ¥Gets the last index where the specified value can be found in the array. Returns - -1if not found.
- function map<U>(fn: (value: T, index: i32, self: StaticArray<T>) => U): Array<U>- 使用数组的每个值调用指定的函数,返回函数返回值的新数组。 - ¥Calls the specified function with every value of the array, returning a new array of the function's return values. 
- function slice<U extends ArrayLike<T> = Array<T>>(start?: i32, end?: i32): U- 返回此静态数组的值(从 - begin(含)到- end(不包括))的浅表副本,作为新的普通数组。如果省略,- end默认为数组末尾。参数- U接受- Array<T>或- StaticArray<T>类型。- ¥Returns a shallow copy of this static array's values from - begininclusive to- endexclusive, as a new normal array. If omitted,- enddefaults to the end of the array. Patameter- Uaccepts- Array<T>or- StaticArray<T>types.
- function some(fn: (value: T, index: i32, self: StaticArray<T>) => bool): bool- 使用数组的每个值调用指定的函数,直到找到函数返回 - true的第一个值,然后返回- true。否则或如果数组为空,则返回- false。- ¥Calls the specified function with every value of the array until it finds the first value for which the function returns - true, returning- true. Returns- falseotherwise or if the array is empty.
- function sort(fn?: (a: T, b: T) => i32): this- 使用指定的比较器函数对数组的值进行就地排序,并在返回数组之前修改数组。比较器返回负值表示 - a < b,返回正值表示- a > b和- 0表示两者相等。与 JavaScript 中执行到字符串的隐式转换不同,比较器默认比较两个- T类型的值。- ¥Sorts the values of the array in place, using the specified comparator function, modifying the array before returning it. The comparator returning a negative value means - a < b, a positive value means- a > band- 0means that both are equal. Unlike in JavaScript, where an implicit conversion to strings is performed, the comparator defaults to compare two values of type- T.
- function reduce<U>( fn: (accumValue: U, currentValue: T, index: i32, self: StaticArray<T>) => U, initialValue: U ): U- 使用数组的每个值调用指定的缩减器函数,从而产生单个返回值。各个前一个 reducer 函数的返回值被记住在 - accumValue中,从- initialValue开始,成为该过程中的最终返回值。- ¥Calls the specified reducer function with each value of the array, resulting in a single return value. The respective previous reducer function's return value is remembered in - accumValue, starting with- initialValue, becoming the final return value in the process.
- function reduceRight<U>( fn: (accumValue: U, currentValue: T, index: i32, self: StaticArray<T>) => U, initialValue: U ): U- 使用数组的每个值从右到左调用指定的缩减器函数,从而产生单个返回值。请参阅 - Array#reduce了解 reducer 函数的签名。- ¥Calls the specified reducer function with each value of the array, from right to left, resulting in a single return value. See - Array#reducefor the reducer function's signature.
- function reverse(): this- 就地反转数组的值,在返回数组之前修改数组。 - ¥Reverses an array's values in place, modifying the array before returning it. 
- function toString(): string- 返回 - join()的结果。- ¥Returns the result of - join().