Uint8Array
A typed array of 8-bit unsigned integer values. The contents are initialized to 0. If the requested number of bytes could not be allocated an exception is raised.
Type Parameters
Section titled “Type Parameters”TArrayBuffer
Section titled “TArrayBuffer”TArrayBuffer extends ArrayBufferLike = ArrayBufferLike
Indexable
Section titled “Indexable”[
index:number]:number
Properties
Section titled “Properties”[toStringTag]
Section titled “[toStringTag]”
readonly[toStringTag]:"Uint8Array"
buffer
Section titled “buffer”
readonlybuffer:TArrayBuffer
The ArrayBuffer instance referenced by the array.
byteLength
Section titled “byteLength”
readonlybyteLength:number
The length in bytes of the array.
byteOffset
Section titled “byteOffset”
readonlybyteOffset:number
The offset in bytes of the array.
BYTES_PER_ELEMENT
Section titled “BYTES_PER_ELEMENT”
readonlyBYTES_PER_ELEMENT:number
The size in bytes of each element in the array.
length
Section titled “length”
readonlylength:number
The length of the array.
Methods
Section titled “Methods”[iterator]()
Section titled “[iterator]()”[iterator]():
ArrayIterator<number>
Returns
Section titled “Returns”ArrayIterator<number>
at(
index):number|undefined
Returns the item located at the specified index.
Parameters
Section titled “Parameters”number
The zero-based index of the desired code unit. A negative index will count back from the last item.
Returns
Section titled “Returns”number | undefined
copyWithin()
Section titled “copyWithin()”copyWithin(
target,start,end?):this
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
Parameters
Section titled “Parameters”target
Section titled “target”number
If target is negative, it is treated as length+target where length is the length of the array.
number
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
number
If not specified, length of the this object is used as its default value.
Returns
Section titled “Returns”this
entries()
Section titled “entries()”entries():
ArrayIterator<[number,number]>
Returns an array of key, value pairs for every entry in the array
Returns
Section titled “Returns”ArrayIterator<[number, number]>
every()
Section titled “every()”every(
predicate,thisArg?):boolean
Determines whether all the members of an array satisfy the specified test.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => unknown
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
thisArg?
Section titled “thisArg?”any
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns
Section titled “Returns”boolean
fill()
Section titled “fill()”fill(
value,start?,end?):this
Changes all array elements from start to end index to a static value and returns the modified array
Parameters
Section titled “Parameters”number
value to fill array section with
start?
Section titled “start?”number
index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.
number
index to stop filling the array at. If end is negative, it is treated as length+end.
Returns
Section titled “Returns”this
filter()
Section titled “filter()”filter(
predicate,thisArg?):Uint8Array<ArrayBuffer>
Returns the elements of an array that meet the condition specified in a callback function.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => any
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
thisArg?
Section titled “thisArg?”any
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
find()
Section titled “find()”find(
predicate,thisArg?):number|undefined
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, obj) => boolean
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
thisArg?
Section titled “thisArg?”any
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns
Section titled “Returns”number | undefined
findIndex()
Section titled “findIndex()”findIndex(
predicate,thisArg?):number
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, obj) => boolean
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
thisArg?
Section titled “thisArg?”any
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns
Section titled “Returns”number
findLast()
Section titled “findLast()”Call Signature
Section titled “Call Signature”findLast<
S>(predicate,thisArg?):S|undefined
Returns the value of the last element in the array where predicate is true, and undefined otherwise.
Type Parameters
Section titled “Type Parameters”S extends number
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => value is S
findLast calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLast immediately returns that element value. Otherwise, findLast returns undefined.
thisArg?
Section titled “thisArg?”any
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns
Section titled “Returns”S | undefined
Call Signature
Section titled “Call Signature”findLast(
predicate,thisArg?):number|undefined
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => unknown
thisArg?
Section titled “thisArg?”any
Returns
Section titled “Returns”number | undefined
findLastIndex()
Section titled “findLastIndex()”findLastIndex(
predicate,thisArg?):number
Returns the index of the last element in the array where predicate is true, and -1 otherwise.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => unknown
findLastIndex calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
thisArg?
Section titled “thisArg?”any
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Returns
Section titled “Returns”number
forEach()
Section titled “forEach()”forEach(
callbackfn,thisArg?):void
Performs the specified action for each element in an array.
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(value, index, array) => void
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
thisArg?
Section titled “thisArg?”any
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Returns
Section titled “Returns”void
includes()
Section titled “includes()”includes(
searchElement,fromIndex?):boolean
Determines whether an array includes a certain element, returning true or false as appropriate.
Parameters
Section titled “Parameters”searchElement
Section titled “searchElement”number
The element to search for.
fromIndex?
Section titled “fromIndex?”number
The position in this array at which to begin searching for searchElement.
Returns
Section titled “Returns”boolean
indexOf()
Section titled “indexOf()”indexOf(
searchElement,fromIndex?):number
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
Parameters
Section titled “Parameters”searchElement
Section titled “searchElement”number
The value to locate in the array.
fromIndex?
Section titled “fromIndex?”number
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Returns
Section titled “Returns”number
join()
Section titled “join()”join(
separator?):string
Adds all the elements of an array separated by the specified separator string.
Parameters
Section titled “Parameters”separator?
Section titled “separator?”string
A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
Returns
Section titled “Returns”string
keys()
Section titled “keys()”keys():
ArrayIterator<number>
Returns an list of keys in the array
Returns
Section titled “Returns”ArrayIterator<number>
lastIndexOf()
Section titled “lastIndexOf()”lastIndexOf(
searchElement,fromIndex?):number
Returns the index of the last occurrence of a value in an array, or -1 if it is not present.
Parameters
Section titled “Parameters”searchElement
Section titled “searchElement”number
The value to locate in the array.
fromIndex?
Section titled “fromIndex?”number
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Returns
Section titled “Returns”number
map(
callbackfn,thisArg?):Uint8Array<ArrayBuffer>
Calls a defined callback function on each element of an array, and returns an array that contains the results.
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(value, index, array) => number
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
thisArg?
Section titled “thisArg?”any
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
reduce()
Section titled “reduce()”Call Signature
Section titled “Call Signature”reduce(
callbackfn):number
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => number
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”reduce(
callbackfn,initialValue):number
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => number
initialValue
Section titled “initialValue”number
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”reduce<
U>(callbackfn,initialValue):U
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => U
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
initialValue
Section titled “initialValue”U
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Returns
Section titled “Returns”U
reduceRight()
Section titled “reduceRight()”Call Signature
Section titled “Call Signature”reduceRight(
callbackfn):number
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => number
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”reduceRight(
callbackfn,initialValue):number
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => number
initialValue
Section titled “initialValue”number
Returns
Section titled “Returns”number
Call Signature
Section titled “Call Signature”reduceRight<
U>(callbackfn,initialValue):U
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
Type Parameters
Section titled “Type Parameters”U
Parameters
Section titled “Parameters”callbackfn
Section titled “callbackfn”(previousValue, currentValue, currentIndex, array) => U
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
initialValue
Section titled “initialValue”U
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Returns
Section titled “Returns”U
reverse()
Section titled “reverse()”reverse():
this
Reverses the elements in an Array.
Returns
Section titled “Returns”this
set(
array,offset?):void
Sets a value or an array of values.
Parameters
Section titled “Parameters”ArrayLike<number>
A typed or untyped array of values to set.
offset?
Section titled “offset?”number
The index in the current array at which the values are to be written.
Returns
Section titled “Returns”void
slice()
Section titled “slice()”slice(
start?,end?):Uint8Array<ArrayBuffer>
Returns a section of an array.
Parameters
Section titled “Parameters”start?
Section titled “start?”number
The beginning of the specified portion of the array.
number
The end of the specified portion of the array. This is exclusive of the element at the index ‘end’.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
some()
Section titled “some()”some(
predicate,thisArg?):boolean
Determines whether the specified callback function returns true for any element of an array.
Parameters
Section titled “Parameters”predicate
Section titled “predicate”(value, index, array) => unknown
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
thisArg?
Section titled “thisArg?”any
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Returns
Section titled “Returns”boolean
sort()
Section titled “sort()”sort(
compareFn?):this
Sorts an array.
Parameters
Section titled “Parameters”compareFn?
Section titled “compareFn?”(a, b) => number
Function used to determine the order of the elements. It is expected to return a negative value if first argument is less than second argument, zero if they’re equal and a positive value otherwise. If omitted, the elements are sorted in ascending order.
[11,2,22,1].sort((a, b) => a - b)Returns
Section titled “Returns”this
subarray()
Section titled “subarray()”subarray(
begin?,end?):Uint8Array<TArrayBuffer>
Gets a new Uint8Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive.
Parameters
Section titled “Parameters”begin?
Section titled “begin?”number
The index of the beginning of the array.
number
The index of the end of the array.
Returns
Section titled “Returns”Uint8Array<TArrayBuffer>
toBase64()
Section titled “toBase64()”toBase64(
options?):string
Encodes the bytes as base64 text.
Parameters
Section titled “Parameters”options?
Section titled “options?”alphabet?
Section titled “alphabet?”"base64" | "base64url"
omitPadding?
Section titled “omitPadding?”boolean
Returns
Section titled “Returns”string
toLocaleString()
Section titled “toLocaleString()”Call Signature
Section titled “Call Signature”toLocaleString():
string
Converts a number to a string by using the current locale.
Returns
Section titled “Returns”string
Call Signature
Section titled “Call Signature”toLocaleString(
locales,options?):string
Parameters
Section titled “Parameters”locales
Section titled “locales”string | string[]
options?
Section titled “options?”NumberFormatOptions
Returns
Section titled “Returns”string
toReversed()
Section titled “toReversed()”toReversed():
Uint8Array<ArrayBuffer>
Copies the array and returns the copy with the elements in reverse order.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
toSorted()
Section titled “toSorted()”toSorted(
compareFn?):Uint8Array<ArrayBuffer>
Copies and sorts the array.
Parameters
Section titled “Parameters”compareFn?
Section titled “compareFn?”(a, b) => number
Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they’re equal, and a positive value otherwise. If omitted, the elements are sorted in ascending order.
const myNums = Uint8Array.from([11, 2, 22, 1]);myNums.toSorted((a, b) => a - b) // Uint8Array(4) [1, 2, 11, 22]Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
toString()
Section titled “toString()”toString():
string
Returns a string representation of an array.
Returns
Section titled “Returns”string
valueOf()
Section titled “valueOf()”valueOf():
this
Returns the primitive value of the specified object.
Returns
Section titled “Returns”this
values()
Section titled “values()”values():
ArrayIterator<number>
Returns an list of values in the array
Returns
Section titled “Returns”ArrayIterator<number>
with()
Section titled “with()”with(
index,value):Uint8Array<ArrayBuffer>
Copies the array and inserts the given number at the provided index.
Parameters
Section titled “Parameters”number
The index of the value to overwrite. If the index is negative, then it replaces from the end of the array.
number
The value to insert into the copied array.
Returns
Section titled “Returns”Uint8Array<ArrayBuffer>
A copy of the original array with the inserted value.