recursal/MDN huggingface dataset:
TypedArray.prototype.map()
==========================

The **`map()`** method of `TypedArray` instances creates a new typed array populated with the results of calling a provided function on every element in the calling typed array. This method has the same algorithm as `Array.prototype.map()`.

Try it
------

Syntax
------


```js
map(callbackFn)
map(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. Its return value is added as a single element in the new typed array. The function is called with the following arguments:

`element`

The current element being processed in the typed array.

`index`

The index of the current element being processed in the typed array.

`array`

The typed array `map()` was called upon.


`thisArg` Optional

A value to use as `this` when executing `callbackFn`. See iterative methods.

### Return value

A new typed array with each element being the result of the callback function.

Description
-----------

See `Array.prototype.map()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Mapping a typed array to a typed array of square roots

 The following code takes a typed array and creates a new typed array containing the
 square roots of the numbers in the first typed array.


```js
const numbers = new Uint8Array([1, 4, 9]);
const roots = numbers.map(Math.sqrt);
// roots is now: Uint8Array [1, 2, 3],
// numbers is still Uint8Array [1, 4, 9]
```

### Mapping a typed array of numbers using a function containing an argument

 The following code shows how `map()` works when a function requiring one
 argument is used with it. The argument will automatically be assigned to each element of
 the typed array as `map()` loops through the original typed array.


```js
const numbers = new Uint8Array([1, 4, 9]);
const doubles = numbers.map((num) => num \* 2);
// doubles is now Uint8Array [2, 8, 18]
// numbers is still Uint8Array [1, 4, 9]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.map |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.map` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.forEach()`
* `TypedArray.from()`
* `Array.prototype.map()`
* `Map`
TypedArray.prototype.buffer
===========================

The **`buffer`** accessor property of `TypedArray` instances returns the `ArrayBuffer` or `SharedArrayBuffer` referenced by this typed array at construction time.

Try it
------

Description
-----------

The `buffer` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when the *TypedArray* is constructed and cannot be changed. *TypedArray* is one of the TypedArray objects.

Because a typed array is a *view* of a buffer, the underlying buffer may be longer than the typed array itself.

Examples
--------

### Using the buffer property


```js
const buffer = new ArrayBuffer(8);
const uint16 = new Uint16Array(buffer);
uint16.buffer; // ArrayBuffer { byteLength: 8 }
```

### Accessing the underlying buffer from a sliced array view


```js
const buffer = new ArrayBuffer(1024);
const arr = new Uint8Array(buffer, 64, 128);
console.log(arr.byteLength); // 128
console.log(arr.buffer.byteLength); // 1024
console.log(arr.buffer === buffer); // true
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-%typedarray%.prototype.buffer |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* JavaScript typed arrays guide
* `TypedArray`
TypedArray.prototype.keys()
===========================

The **`keys()`** method of `TypedArray` instances returns a new *array iterator* object that contains the keys for each index in the typed array. This method has the same algorithm as `Array.prototype.keys()`.

Try it
------

Syntax
------


```js
keys()
```

### Parameters

None.

### Return value

A new iterable iterator object.

Description
-----------

See `Array.prototype.keys()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Iteration using for...of loop


```js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const arrKeys = arr.keys();
for (const n of arrKeys) {
  console.log(n);
}
```

### Alternative iteration


```js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const arrKeys = arr.keys();
console.log(arrKeys.next().value); // 0
console.log(arrKeys.next().value); // 1
console.log(arrKeys.next().value); // 2
console.log(arrKeys.next().value); // 3
console.log(arrKeys.next().value); // 4
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.keys |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.keys` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.entries()`
* `TypedArray.prototype.values()`
* `TypedArray.prototype[@@iterator]()`
* `Array.prototype.keys()`
* Iteration protocols
TypedArray.prototype.byteOffset
===============================

The **`byteOffset`** accessor property of `TypedArray` instances returns the offset (in bytes) of this typed array from the start of its `ArrayBuffer` or `SharedArrayBuffer`.

Description
-----------

The `byteOffset` property is an accessor property whose set accessor function is `undefined`, meaning that you can only read this property. The value is established when a *TypedArray* is constructed and cannot be changed. *TypedArray* is one of the TypedArray objects.

Examples
--------

### Using the byteOffset property


```js
const buffer = new ArrayBuffer(8);

const uint8array1 = new Uint8Array(buffer);
uint8array1.byteOffset; // 0 (no offset specified)

const uint8array2 = new Uint8Array(buffer, 3);
uint8array2.byteOffset; // 3 (as specified when constructing Uint8Array)
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-get-%typedarray%.prototype.byteoffset |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* JavaScript typed arrays guide
* `TypedArray`
TypedArray.prototype.reverse()
==============================

The **`reverse()`** method of `TypedArray` instances reverses a typed array *in place* and returns the reference to the same typed array, the first typed array element now becoming the last, and the last typed array element becoming the first. In other words, elements order in the typed array will be turned towards the direction opposite to that previously stated. This method has the same algorithm as `Array.prototype.reverse()`.

Try it
------

Syntax
------


```js
reverse()
```

### Parameters

None.

### Return value

The reference to the original typed array, now reversed. Note that the typed array is reversed *in place*, and no copy is made.

Description
-----------

See `Array.prototype.reverse()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using reverse()


```js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();

console.log(uint8); // Uint8Array [3, 2, 1]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.reverse |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.reverse` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.join()`
* `TypedArray.prototype.sort()`
* `TypedArray.prototype.toReversed()`
* `Array.prototype.reverse()`
TypedArray.prototype.indexOf()
==============================

The **`indexOf()`** method of `TypedArray` instances returns the first index at which a given element can be found in the typed array, or -1 if it is not present. This method has the same algorithm as `Array.prototype.indexOf()`.

Try it
------

Syntax
------


```js
indexOf(searchElement)
indexOf(searchElement, fromIndex)
```

### Parameters

`searchElement`

Element to locate in the typed array.

`fromIndex` Optional

Zero-based index at which to start searching, converted to an integer.

### Return value

The first index of `searchElement` in the typed array; `-1` if not found.

Description
-----------

See `Array.prototype.indexOf()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using indexOf()


```js
const uint8 = new Uint8Array([2, 5, 9]);
uint8.indexOf(2); // 0
uint8.indexOf(7); // -1
uint8.indexOf(9, 2); // 2
uint8.indexOf(2, -1); // -1
uint8.indexOf(2, -3); // 0
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.indexof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.indexOf` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.findIndex()`
* `TypedArray.prototype.findLastIndex()`
* `TypedArray.prototype.lastIndexOf()`
* `Array.prototype.indexOf()`
* `String.prototype.indexOf()`
TypedArray.prototype.lastIndexOf()
==================================

The **`lastIndexOf()`** method of `TypedArray` instances returns the last index at which a given element can be found in the typed array, or -1 if it is not present. The typed array is searched backwards, starting at `fromIndex`. This method has the same algorithm as `Array.prototype.lastIndexOf()`.

Try it
------

Syntax
------


```js
lastIndexOf(searchElement)
lastIndexOf(searchElement, fromIndex)
```

### Parameters

`searchElement`

Element to locate in the typed array.

`fromIndex` Optional

Zero-based index at which to start searching backwards, converted to an integer.

### Return value

The last index of `searchElement` in the typed array; `-1` if not found.

Description
-----------

See `Array.prototype.lastIndexOf()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using lastIndexOf()


```js
const uint8 = new Uint8Array([2, 5, 9, 2]);
uint8.lastIndexOf(2); // 3
uint8.lastIndexOf(7); // -1
uint8.lastIndexOf(2, 3); // 3
uint8.lastIndexOf(2, 2); // 0
uint8.lastIndexOf(2, -2); // 0
uint8.lastIndexOf(2, -1); // 3
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.lastindexof |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.lastIndexOf` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.findIndex()`
* `TypedArray.prototype.findLastIndex()`
* `TypedArray.prototype.indexOf()`
* `Array.prototype.lastIndexOf()`
* `String.prototype.lastIndexOf()`
TypedArray.BYTES\_PER\_ELEMENT
==============================

The **`TypedArray.BYTES_PER_ELEMENT`** static data property represents the size in bytes of each element in a typed array.

Try it
------

Value
-----

A number whose value depends on the type of `TypedArray`.

| Property attributes of `TypedArray.BYTES_PER_ELEMENT` |
| --- |
| Writable | no |
| Enumerable | no |
| Configurable | no |

Description
-----------

`TypedArray` objects differ from each other in the number of bytes per element and in the way the bytes are interpreted. The `BYTES_PER_ELEMENT` constant contains the number of bytes each element in the given `TypedArray` has.

The `BYTES_PER_ELEMENT` property is both an *instance property* and a *static property*. It's available on both `TypedArray` subclass constructors and on instances of those constructors.

As an instance property, `BYTES_PER_ELEMENT` is defined on the constructor's `prototype`.


```js
console.log(Object.hasOwn(Int8Array.prototype, "BYTES\_PER\_ELEMENT")); // true
```

Examples
--------

### Using BYTES\_PER\_ELEMENT

As a static property:


```js
Int8Array.BYTES\_PER\_ELEMENT; // 1
Uint8Array.BYTES\_PER\_ELEMENT; // 1
Uint8ClampedArray.BYTES\_PER\_ELEMENT; // 1
Int16Array.BYTES\_PER\_ELEMENT; // 2
Uint16Array.BYTES\_PER\_ELEMENT; // 2
Int32Array.BYTES\_PER\_ELEMENT; // 4
Uint32Array.BYTES\_PER\_ELEMENT; // 4
Float32Array.BYTES\_PER\_ELEMENT; // 4
Float64Array.BYTES\_PER\_ELEMENT; // 8
BigInt64Array.BYTES\_PER\_ELEMENT; // 8
BigUint64Array.BYTES\_PER\_ELEMENT; // 8
```


As an instance property:


```js
new Int8Array([]).BYTES\_PER\_ELEMENT; // 1
new Uint8Array([]).BYTES\_PER\_ELEMENT; // 1
new Uint8ClampedArray([]).BYTES\_PER\_ELEMENT; // 1
new Int16Array([]).BYTES\_PER\_ELEMENT; // 2
new Uint16Array([]).BYTES\_PER\_ELEMENT; // 2
new Int32Array([]).BYTES\_PER\_ELEMENT; // 4
new Uint32Array([]).BYTES\_PER\_ELEMENT; // 4
new Float32Array([]).BYTES\_PER\_ELEMENT; // 4
new Float64Array([]).BYTES\_PER\_ELEMENT; // 8
new BigInt64Array([]).BYTES\_PER\_ELEMENT; // 8
new BigUint64Array([]).BYTES\_PER\_ELEMENT; // 8
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-typedarray.bytes\_per\_element |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* JavaScript typed arrays guide
* `TypedArray`
TypedArray.prototype.forEach()
==============================

The **`forEach()`** method of `TypedArray` instances executes a provided function once for each typed array element. This method has the same algorithm as `Array.prototype.forEach()`.

Try it
------

Syntax
------


```js
forEach(callbackFn)
forEach(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. Its return value is discarded. The function is called with the following arguments:

`element`

The current element being processed in the typed array.

`index`

The index of the current element being processed in the typed array.

`array`

The typed array `forEach()` was called upon.


`thisArg` Optional

A value to use as `this` when executing `callbackFn`. See iterative methods.

### Return value

None (`undefined`).

Description
-----------

See `Array.prototype.forEach()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Logging the contents of a typed array

The following code logs a line for each element in a typed array:


```js
function logArrayElements(element, index, array) {
  console.log(`a[${index}] = ${element}`);
}

new Uint8Array([0, 1, 2, 3]).forEach(logArrayElements);
// Logs:
// a[0] = 0
// a[1] = 1
// a[2] = 2
// a[3] = 3
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.foreach |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.forEach` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.find()`
* `TypedArray.prototype.map()`
* `TypedArray.prototype.filter()`
* `TypedArray.prototype.every()`
* `TypedArray.prototype.some()`
* `Array.prototype.forEach()`
* `Map.prototype.forEach()`
* `Set.prototype.forEach()`
TypedArray.of()
===============

 The **`TypedArray.of()`** static method creates a new
 typed array from a variable number of arguments. This method is nearly the same as
 `Array.of()`.

Try it
------

Syntax
------


```js
TypedArray.of()
TypedArray.of(element1)
TypedArray.of(element1, element2)
TypedArray.of(element1, element2, /\* …, \*/ elementN)
```


Where `TypedArray` is one of:

* `Int8Array`
* `Uint8Array`
* `Uint8ClampedArray`
* `Int16Array`
* `Uint16Array`
* `Int32Array`
* `Uint32Array`
* `Float32Array`
* `Float64Array`
* `BigInt64Array`
* `BigUint64Array`
### Parameters

`element1`, …, `elementN`

Elements used to create the typed array.

### Return value

A new `TypedArray` instance.

Description
-----------

 See `Array.of()` for more details. There are some subtle distinctions between `Array.of()` and
 `TypedArray.of()`:

* If the `this` value passed to `TypedArray.of()` is not a constructor, `TypedArray.from()` will throw a `TypeError`, while `Array.of()` defaults to creating a new `Array`.
* `TypedArray.of()` uses `[[Set]]` while `Array.of()` uses `[[DefineOwnProperty]]`. Hence, when working with `Proxy` objects, it calls `handler.set()` to create new elements rather than `handler.defineProperty()`.
Examples
--------

### Using of()


```js
Uint8Array.of(1); // Uint8Array [ 1 ]
Int8Array.of("1", "2", "3"); // Int8Array [ 1, 2, 3 ]
Float32Array.of(1, 2, 3); // Float32Array [ 1, 2, 3 ]
Int16Array.of(undefined); // Int16Array [ 0 ]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.of |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.of` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.from()`
* `Array.of()`
TypedArray.prototype.reduce()
=============================

The **`reduce()`** method of `TypedArray` instances executes a user-supplied "reducer" callback function on each element of the typed array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the typed array is a single value. This method has the same algorithm as `Array.prototype.reduce()`.

Try it
------

Syntax
------


```js
reduce(callbackFn)
reduce(callbackFn, initialValue)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. Its return value becomes the value of the `accumulator` parameter on the next invocation of `callbackFn`. For the last invocation, the return value becomes the return value of `reduce()`. The function is called with the following arguments:

`accumulator`

The value resulting from the previous call to `callbackFn`. On the first call, its value is `initialValue` if the latter is specified; otherwise its value is `array[0]`.

`currentValue`

The value of the current element. On the first call, its value is `array[0]` if `initialValue` is specified; otherwise its value is `array[1]`.

`currentIndex`

The index position of `currentValue` in the typed array. On the first call, its value is `0` if `initialValue` is specified, otherwise `1`.

`array`

The typed array `reduce()` was called upon.


`initialValue` Optional

 A value to which `accumulator` is initialized the first time the callback is called.
 If `initialValue` is specified, `callbackFn` starts executing with the first value in the typed array as `currentValue`.
 If `initialValue` is *not* specified, `accumulator` is initialized to the first value in the typed array, and `callbackFn` starts executing with the second value in the typed array as `currentValue`. In this case, if the typed array is empty (so that there's no first value to return as `accumulator`), an error is thrown.


### Return value

The value that results from running the "reducer" callback function to completion over the entire typed array.

### Exceptions

`TypeError`

Thrown if the typed array contains no elements and `initialValue` is not provided.

Description
-----------

See `Array.prototype.reduce()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Sum up all values within an array


```js
const total = new Uint8Array([0, 1, 2, 3]).reduce((a, b) => a + b);
// total === 6
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.reduce |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.reduce` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.map()`
* `TypedArray.prototype.reduceRight()`
* `Array.prototype.reduce()`
* `Object.groupBy()`
* `Map.groupBy()`
TypedArray.prototype.join()
===========================

The **`join()`** method of `TypedArray` instances creates and returns a new string by concatenating all of the elements in this typed array, separated by commas or a specified separator string. If the typed array has only one item, then that item will be returned without using the separator. This method has the same algorithm as `Array.prototype.join()`.

Try it
------

Syntax
------


```js
join()
join(separator)
```

### Parameters

`separator` Optional

A string to separate each pair of adjacent elements of the typed array. If omitted, the typed array elements are separated with a comma (",").

### Return value

A string with all typed array elements joined. If `array.length` is `0`, the empty string is returned.

Description
-----------

See `Array.prototype.join()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using join()


```js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.join(); // '1,2,3'
uint8.join(" / "); // '1 / 2 / 3'
uint8.join(""); // '123'
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.join |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.join` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.toString()`
* `Array.prototype.join()`
* `String.prototype.split()`
TypedArray.prototype.fill()
===========================

The **`fill()`** method of `TypedArray` instances changes all elements within a range of indices in a typed array to a static value. It returns the modified typed array. This method has the same algorithm as `Array.prototype.fill()`.

Try it
------

Syntax
------


```js
fill(value)
fill(value, start)
fill(value, start, end)
```

### Parameters

`value`

Value to fill the typed array with.

`start` Optional

Zero-based index at which to start filling, converted to an integer.

`end` Optional

Zero-based index at which to end filling, converted to an integer. `fill()` fills up to but not including `end`.

### Return value

The modified typed array, filled with `value`.

Description
-----------

See `Array.prototype.fill()` for more details. This method is not generic and can only be called on typed array instances.

Examples
--------

### Using fill()


```js
new Uint8Array([1, 2, 3]).fill(4); // Uint8Array [4, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1); // Uint8Array [1, 4, 4]
new Uint8Array([1, 2, 3]).fill(4, 1, 2); // Uint8Array [1, 4, 3]
new Uint8Array([1, 2, 3]).fill(4, 1, 1); // Uint8Array [1, 2, 3]
new Uint8Array([1, 2, 3]).fill(4, -3, -2); // Uint8Array [4, 2, 3]
```

Specifications
--------------

| Specification |
| --- |
| ECMAScript Language Specification # sec-%typedarray%.prototype.fill |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Polyfill of `TypedArray.prototype.fill` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `Array.prototype.fill()`