KIT

ReadonlyUint8Array

Uint8Array 的只读变体。

此类型通过省略可变方法(如 copyWithinfillreversesetsort)来防止修改数组,同时仍然允许对元素进行索引访问。

示例

const bytes: ReadonlyUint8Array = new Uint8Array([1, 2, 3]);
console.log(bytes[0]); // 1
bytes[0] = 42; // 类型错误:无法分配给“0”,因为它是一个只读属性。

继承自

可索引

[n: number]: number

属性

属性修饰符类型描述继承自
[toStringTag]readonly"Uint8Array"-Omit.[toStringTag]
bufferreadonlyArrayBufferLike数组引用的 ArrayBuffer 实例。Omit.buffer
byteLengthreadonlynumber数组的字节长度。Omit.byteLength
byteOffsetreadonlynumber数组的字节偏移量。Omit.byteOffset
BYTES_PER_ELEMENTreadonlynumber数组中每个元素的大小(以字节为单位)。Omit.BYTES_PER_ELEMENT
lengthreadonlynumber数组的长度。Omit.length

方法

[iterator]()

[iterator](): ArrayIterator<number>

返回

ArrayIterator<number>

继承自

Omit.[iterator]


entries()

entries(): ArrayIterator<[number, number]>

返回数组中每个条目的键值对数组

返回

ArrayIterator<[number, number]>

继承自

Omit.entries


every()

every(predicate, thisArg?): boolean

确定数组的所有成员是否满足指定的测试。

参数

参数类型描述
predicate(value, index, array) => unknown一个最多接受三个参数的函数。 every 方法为数组中的每个元素调用 predicate 函数,直到谓词返回一个可强制转换为布尔值 false 的值,或者直到数组结束。
thisArg?any一个对象,this 关键字可以在 predicate 函数中引用它。 如果省略 thisArg,则使用 undefined 作为 this 值。

返回

boolean

继承自

Omit.every


filter()

filter(predicate, thisArg?): Uint8Array<ArrayBuffer>

返回满足回调函数中指定条件的数组元素。

参数

参数类型描述
predicate(value, index, array) => any一个最多接受三个参数的函数。 filter 方法为数组中的每个元素调用 predicate 函数一次。
thisArg?any一个对象,this 关键字可以在 predicate 函数中引用它。 如果省略 thisArg,则使用 undefined 作为 this 值。

返回

Uint8Array<ArrayBuffer>

继承自

Omit.filter


find()

find(predicate, thisArg?): undefined | number

返回数组中 predicate 为 true 的第一个元素的值,否则返回 undefined

参数

参数类型描述
predicate(value, index, obj) => booleanfind 为数组的每个元素按升序调用 predicate 一次,直到找到一个 predicate 返回 true 的元素。 如果找到这样的元素,find 立即返回该元素值。 否则,find 返回 undefined
thisArg?any如果提供,它将用作 predicate 每次调用的 this 值。 如果未提供,则改用 undefined

返回

undefined | number

继承自

Omit.find


findIndex()

findIndex(predicate, thisArg?): number

返回数组中 predicate 为 true 的第一个元素的索引,否则返回 -1。

参数

参数类型描述
predicate(value, index, obj) => booleanfind 为数组的每个元素按升序调用 predicate 一次,直到找到一个 predicate 返回 true 的元素。 如果找到这样的元素,findIndex 立即返回该元素索引。 否则,findIndex 返回 -1。
thisArg?any如果提供,它将用作 predicate 每次调用的 this 值。 如果未提供,则改用 undefined

返回

number

继承自

Omit.findIndex


forEach()

forEach(callbackfn, thisArg?): void

为数组中的每个元素执行指定的操作。

参数

参数类型描述
callbackfn(value, index, array) => void一个最多接受三个参数的函数。 forEach 为数组中的每个元素调用 callbackfn 函数一次。
thisArg?any一个对象,this 关键字可以在 callbackfn 函数中引用它。 如果省略 thisArg,则使用 undefined 作为 this 值。

返回

void

继承自

Omit.forEach


includes()

includes(searchElement, fromIndex?): boolean

确定数组是否包含某个元素,并根据需要返回 true 或 false。

参数

参数类型描述
searchElementnumber要搜索的元素。
fromIndex?number在此数组中开始搜索 searchElement 的位置。

返回

boolean

继承自

Omit.includes


indexOf()

indexOf(searchElement, fromIndex?): number

返回数组中某个值第一次出现的索引。

参数

参数类型描述
searchElementnumber要在数组中查找的值。
fromIndex?number开始搜索的数组索引。 如果省略 fromIndex,则搜索从索引 0 开始。

返回

number

继承自

Omit.indexOf


join()

join(separator?): string

添加由指定的分隔符字符串分隔的数组的所有元素。

参数

参数类型描述
separator?string用于在生成的字符串中将数组的一个元素与下一个元素分隔开的字符串。 如果省略,则数组元素用逗号分隔。

返回

string

继承自

Omit.join


keys()

keys(): ArrayIterator<number>

返回数组中键的列表

返回

ArrayIterator<number>

继承自

Omit.keys


lastIndexOf()

lastIndexOf(searchElement, fromIndex?): number

返回数组中某个值最后一次出现的索引。

参数

参数类型描述
searchElementnumber要在数组中查找的值。
fromIndex?number开始搜索的数组索引。 如果省略 fromIndex,则搜索从索引 0 开始。

返回

number

继承自

Omit.lastIndexOf


map()

map(callbackfn, thisArg?): Uint8Array<ArrayBuffer>

对数组的每个元素调用定义的回调函数,并返回一个包含结果的数组。

参数

参数类型描述
callbackfn(value, index, array) => number一个最多接受三个参数的函数。 map 方法为数组中的每个元素调用 callbackfn 函数一次。
thisArg?any一个对象,this 关键字可以在 callbackfn 函数中引用它。 如果省略 thisArg,则使用 undefined 作为 this 值。

返回

Uint8Array<ArrayBuffer>

继承自

Omit.map


reduce()

调用签名

reduce(callbackfn): number

为数组中的所有元素调用指定的回调函数。 回调函数的返回值是累积结果,并在下一次调用回调函数时作为参数提供。

参数
参数类型描述
callbackfn(previousValue, currentValue, currentIndex, array) => number一个最多接受四个参数的函数。 reduce 方法为数组中的每个元素调用 callbackfn 函数一次。
返回

number

继承自

Omit.reduce

调用签名

reduce(callbackfn, initialValue): number

参数
参数类型
callbackfn(previousValue, currentValue, currentIndex, array) => number
initialValuenumber
返回

number

继承自

Omit.reduce

调用签名

reduce<U>(callbackfn, initialValue): U

为数组中的所有元素调用指定的回调函数。 回调函数的返回值是累积结果,并在下一次调用回调函数时作为参数提供。

类型参数
类型参数
U
参数
参数类型描述
callbackfn(previousValue, currentValue, currentIndex, array) => U一个最多接受四个参数的函数。 reduce 方法为数组中的每个元素调用 callbackfn 函数一次。
initialValueU如果指定了 initialValue,则将其用作起始累积的初始值。 对 callbackfn 函数的第一次调用提供此值作为参数,而不是数组值。
返回

U

继承自

Omit.reduce


reduceRight()

调用签名

reduceRight(callbackfn): number

按降序为数组中的所有元素调用指定的回调函数。 回调函数的返回值是累积结果,并在下一次调用回调函数时作为参数提供。

参数
参数类型描述
callbackfn(previousValue, currentValue, currentIndex, array) => number一个最多接受四个参数的函数。 reduceRight 方法为数组中的每个元素调用 callbackfn 函数一次。
返回

number

继承自

Omit.reduceRight

调用签名

reduceRight(callbackfn, initialValue): number

参数
参数类型
callbackfn(previousValue, currentValue, currentIndex, array) => number
initialValuenumber
返回

number

继承自

Omit.reduceRight

调用签名

reduceRight<U>(callbackfn, initialValue): U

按降序为数组中的所有元素调用指定的回调函数。 回调函数的返回值是累积结果,并在下一次调用回调函数时作为参数提供。

类型参数
类型参数
U
参数
参数类型描述
callbackfn(previousValue, currentValue, currentIndex, array) => U一个最多接受四个参数的函数。 reduceRight 方法为数组中的每个元素调用 callbackfn 函数一次。
initialValueU如果指定了 initialValue,则将其用作起始累积的初始值。 对 callbackfn 函数的第一次调用提供此值作为参数,而不是数组值。
返回

U

继承自

Omit.reduceRight


slice()

slice(start?, end?): Uint8Array<ArrayBuffer>

返回数组的一部分。

参数

参数类型描述
start?number数组的指定部分的开头。
end?number数组的指定部分的结尾。 这不包括索引“end”处的元素。

返回

Uint8Array<ArrayBuffer>

继承自

Omit.slice


some()

some(predicate, thisArg?): boolean

确定指定的回调函数是否为数组的任何元素返回 true。

参数

参数类型描述
predicate(value, index, array) => unknown一个最多接受三个参数的函数。 some 方法为数组中的每个元素调用 predicate 函数,直到谓词返回一个可强制转换为布尔值 true 的值,或者直到数组结束。
thisArg?any一个对象,this 关键字可以在 predicate 函数中引用它。 如果省略 thisArg,则使用 undefined 作为 this 值。

返回

boolean

继承自

Omit.some


subarray()

subarray(begin?, end?): Uint8Array<ArrayBufferLike>

获取此数组的 ArrayBuffer 存储的新 Uint8Array 视图,引用从 begin(包括)到 end(不包括)的元素。

参数

参数类型描述
begin?number数组开头的索引。
end?number数组结尾的索引。

返回

Uint8Array<ArrayBufferLike>

继承自

Omit.subarray


toLocaleString()

调用签名

toLocaleString(): string

通过使用当前区域设置将数字转换为字符串。

返回

string

继承自

Omit.toLocaleString

调用签名

toLocaleString(locales, options?): string

参数
参数类型
localesstring | string[]
options?NumberFormatOptions
返回

string

继承自

Omit.toLocaleString


toString()

toString(): string

返回数组的字符串表示形式。

返回

string

继承自

Omit.toString


valueOf()

valueOf(): this

返回指定对象的原始值。

返回

this

继承自

Omit.valueOf


values()

values(): ArrayIterator<number>

返回数组中值的列表

返回

ArrayIterator<number>

继承自

Omit.values