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

The **`toString()`** method of `TypedArray` instances returns a string representing the specified typed array and its elements. This method has the same algorithm as `Array.prototype.toString()`.

Try it
------

Syntax
------


```js
toString()
```

### Parameters

None.

### Return value

A string representing the elements of the typed array.

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

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

Examples
--------

### Converting a typed array to a string


```js
const uint8 = new Uint8Array([1, 2, 3]);
// Explicit conversion
console.log(uint8.toString()); // 1,2,3
// Implicit conversion
console.log(`${uint8}`); // 1,2,3
```

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

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

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.join()`
* `TypedArray.prototype.toLocaleString()`
* `Array.prototype.toString()`
* `String.prototype.toString()`
TypedArray.prototype.length
===========================

The **`length`** accessor property of `TypedArray` instances returns the length (in elements) of this typed array.

Try it
------

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

The `length` 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. If the *TypedArray* is not specifying a `byteOffset` or a `length`, the length of the referenced `ArrayBuffer` will be returned. *TypedArray* is one of the TypedArray objects.

Examples
--------

### Using the `length` property


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

let uint8 = new Uint8Array(buffer);
uint8.length; // 8 (matches the length of the buffer)

uint8 = new Uint8Array(buffer, 1, 5);
uint8.length; // 5 (as specified when constructing the Uint8Array)

uint8 = new Uint8Array(buffer, 2);
uint8.length; // 6 (due to the offset of the constructed Uint8Array)
```

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

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

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.findIndex()
================================

The **`findIndex()`** method of `TypedArray` instances returns the index of the first element in a typed array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned. This method has the same algorithm as `Array.prototype.findIndex()`.

Try it
------

Syntax
------


```js
findIndex(callbackFn)
findIndex(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. 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 `findIndex()` was called upon.


`thisArg` Optional

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

### Return value

The index of the first element in the typed array that passes the test. Otherwise, `-1`.

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

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

Examples
--------

### Find the index of a prime number in a typed array

 The following example finds the index of an element in the typed array that is a prime
 number (or returns `-1` if there is no prime number).


```js
function isPrime(element, index, array) {
  let start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1) {
      return false;
    }
  }
  return element > 1;
}

const uint8 = new Uint8Array([4, 6, 8, 12]);
const uint16 = new Uint16Array([4, 6, 7, 12]);

console.log(uint8.findIndex(isPrime)); // -1, not found
console.log(uint16.findIndex(isPrime)); // 2
```

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

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

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

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

See also
--------

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

 The **`set()`** method of `TypedArray` instances stores multiple values in the typed
 array, reading input values from a specified array.

Try it
------

Syntax
------


```js
set(array)
set(array, targetOffset)

set(typedarray)
set(typedarray, targetOffset)
```

### Parameters

`array`

 The array from which to copy values. All values from the source array are copied
 into the target array, unless the length of the source array plus the target offset exceeds
 the length of the target array, in which case an exception is thrown.


`typedarray`

 If the source array is a typed array, the two arrays may share the same underlying
 `ArrayBuffer`; the JavaScript engine will intelligently
 **copy** the source range of the buffer to the destination range.


`targetOffset` Optional

 The offset into the target array at which to begin writing values from the source
 array. If this value is omitted, 0 is assumed (that is, the source array will
 overwrite values in the target array starting at index 0).


### Return value

None (`undefined`).

### Exceptions

`RangeError`

Thrown in one of the following cases:

* An element will be stored beyond the end of the typed array, either because `targetOffset` is too large or because `array` or `typedarray` is too large.
* `targetOffset` is negative.

Examples
--------

### Using set()


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

uint8.set([1, 2, 3], 3);

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

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

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

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

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

See also
--------

* Polyfill of `TypedArray.prototype.set` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `ArrayBuffer`
TypedArray.prototype.copyWithin()
=================================

The **`copyWithin()`** method of `TypedArray` instances shallow copies part of this typed array to another location in the same typed array and returns this typed array without modifying its length. This method has the same algorithm as `Array.prototype.copyWithin()`.

Try it
------

Syntax
------


```js
copyWithin(target, start)
copyWithin(target, start, end)
```

### Parameters

`target`

Zero-based index at which to copy the sequence to, converted to an integer. This corresponds to where the element at `start` will be copied to, and all elements between `start` and `end` are copied to succeeding indices.

`start`

Zero-based index at which to start copying elements from, converted to an integer.

`end` Optional

Zero-based index at which to end copying elements from, converted to an integer. `copyWithin()` copies up to but not including `end`.

### Return value

The modified typed array.

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

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

Examples
--------

### Using copyWithin()


```js
const buffer = new ArrayBuffer(8);
const uint8 = new Uint8Array(buffer);
uint8.set([1, 2, 3]);
console.log(uint8); // Uint8Array [ 1, 2, 3, 0, 0, 0, 0, 0 ]
uint8.copyWithin(3, 0, 3);
console.log(uint8); // Uint8Array [ 1, 2, 3, 1, 2, 3, 0, 0 ]
```

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

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

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

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

See also
--------

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

The **`filter()`** method of `TypedArray` instances creates a copy of a portion of a given typed array, filtered down to just the elements from the given typed array that pass the test implemented by the provided function. This method has the same algorithm as `Array.prototype.filter()`.

Try it
------

Syntax
------


```js
filter(callbackFn)
filter(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. It should return a truthy value to keep the element in the resulting typed array, and a falsy value otherwise. 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 `filter()` was called upon.


`thisArg` Optional

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

### Return value

A copy of the given typed array containing just the elements that pass the test. If no elements pass the test, an empty typed array is returned.

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

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

Examples
--------

### Filtering out all small values

The following example uses `filter()` to create a filtered typed array that has all elements with values less than 10 removed.


```js
function isBigEnough(element, index, array) {
  return element >= 10;
}
new Uint8Array([12, 5, 8, 130, 44]).filter(isBigEnough);
// Uint8Array [ 12, 130, 44 ]
```

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

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

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

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

See also
--------

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

The **`values()`** method of `TypedArray` instances returns a new *array iterator* object that iterates the value of each item in the typed array. This method has the same algorithm as `Array.prototype.values()`.

Try it
------

Syntax
------


```js
values()
```

### Parameters

None.

### Return value

A new iterable iterator object.

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

See `Array.prototype.values()` 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 values = arr.values();
for (const n of values) {
  console.log(n);
}
```

### Alternative iteration


```js
const arr = new Uint8Array([10, 20, 30, 40, 50]);
const values = arr.values();
console.log(values.next().value); // 10
console.log(values.next().value); // 20
console.log(values.next().value); // 30
console.log(values.next().value); // 40
console.log(values.next().value); // 50
```

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

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

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

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

See also
--------

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

The **`byteLength`** accessor property of `TypedArray` instances returns the length (in bytes) of this typed array.

Try it
------

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

The `byteLength` 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. If the *TypedArray* is not specifying a `byteOffset` or a `length`, the `length` of the referenced `ArrayBuffer` will be returned. *TypedArray* is one of the TypedArray objects.

Examples
--------

### Using the byteLength property


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

const uint8 = new Uint8Array(buffer);
uint8.byteLength; // 8 (matches the byteLength of the buffer)

const uint8newLength = new Uint8Array(buffer, 1, 5);
uint8newLength.byteLength; // 5 (as specified when constructing the Uint8Array)

const uint8offSet = new Uint8Array(buffer, 2);
uint8offSet.byteLength; // 6 (due to the offset of the constructed Uint8Array)
```

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

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

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.with()
===========================

The **`with()`** method of `TypedArray` instances is the copying version of using the bracket notation to change the value of a given index. It returns a new typed array with the element at the given index replaced with the given value. This method has the same algorithm as `Array.prototype.with()`.

Syntax
------


```js
arrayInstance.with(index, value)
```

### Parameters

`index`

Zero-based index at which to change the typed array, converted to an integer.

`value`

Any value to be assigned to the given index.

### Return value

A new typed array with the element at `index` replaced with `value`.

### Exceptions

`RangeError`

Thrown if `index >= array.length` or `index < -array.length`.

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

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

Examples
--------

### Using with()


```js
const arr = new Uint8Array([1, 2, 3, 4, 5]);
console.log(arr.with(2, 6)); // Uint8Array [1, 2, 6, 4, 5]
console.log(arr); // Uint8Array [1, 2, 3, 4, 5]
```

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

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

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

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

See also
--------

* Polyfill of `TypedArray.prototype.with` in `core-js`
* JavaScript typed arrays guide
* `TypedArray.prototype.toReversed()`
* `TypedArray.prototype.toSorted()`
* `TypedArray.prototype.at()`
* `Array.prototype.with()`
TypedArray.prototype.toLocaleString()
=====================================

The **`toLocaleString()`** method of `TypedArray` instances returns a string representing the elements of the typed array. The elements are converted to strings using their `toLocaleString` methods and these strings are separated by a locale-specific string (such as a comma ","). This method has the same algorithm as `Array.prototype.toLocaleString()`.

Try it
------

Syntax
------


```js
toLocaleString()
toLocaleString(locales)
toLocaleString(locales, options)
```

### Parameters

`locales` Optional

A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the `locales` argument, see the parameter description on the `Intl` main page.

`options` Optional

An object with configuration properties. See `Number.prototype.toLocaleString()`.

### Return value

A string representing the elements of the typed array.

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

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

Examples
--------

### Using toLocaleString()


```js
const uint = new Uint32Array([2000, 500, 8123, 12, 4212]);

uint.toLocaleString();
// if run in a de-DE locale
// "2.000,500,8.123,12,4.212"

uint.toLocaleString("en-US");
// "2,000,500,8,123,12,4,212"

uint.toLocaleString("ja-JP", { style: "currency", currency: "JPY" });
// "￥2,000,￥500,￥8,123,￥12,￥4,212"
```

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

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

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.toString()`
* `Array.prototype.toLocaleString()`
* `Intl`
* `Intl.ListFormat`
* `Number.prototype.toLocaleString()`
TypedArray.prototype.find()
===========================

The **`find()`** method of `TypedArray` instances returns the first element in the provided typed array that satisfies the provided testing function. If no values satisfy the testing function, `undefined` is returned. This method has the same algorithm as `Array.prototype.find()`.

Try it
------

Syntax
------


```js
find(callbackFn)
find(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. It should return a truthy value to indicate a matching element has been found, and a falsy value otherwise. 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 `find()` was called upon.


`thisArg` Optional

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

### Return value

 The first element in the typed array that satisfies the provided testing function.
 Otherwise, `undefined` is returned.

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

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

Examples
--------

### Find a prime number in a typed array

The following example finds an element in the typed array that is a prime number (or returns `undefined` if there is no prime number).


```js
function isPrime(element, index, array) {
  let start = 2;
  while (start <= Math.sqrt(element)) {
    if (element % start++ < 1) {
      return false;
    }
  }
  return element > 1;
}

const uint8 = new Uint8Array([4, 5, 8, 12]);
console.log(uint8.find(isPrime)); // 5
```

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

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

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

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

See also
--------

* Polyfill of `TypedArray.prototype.find` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.findIndex()`
* `TypedArray.prototype.findLast()`
* `TypedArray.prototype.findLastIndex()`
* `TypedArray.prototype.includes()`
* `TypedArray.prototype.filter()`
* `TypedArray.prototype.every()`
* `TypedArray.prototype.some()`
* `Array.prototype.find()`
TypedArray.prototype.some()
===========================

The **`some()`** method of `TypedArray` instances tests whether at least one element in the typed array passes the test implemented by the provided function. It returns true if, in the typed array, it finds an element for which the provided function returns true; otherwise it returns false. It doesn't modify the typed array. This method has the same algorithm as `Array.prototype.some()`.

Try it
------

Syntax
------


```js
some(callbackFn)
some(callbackFn, thisArg)
```

### Parameters

`callbackFn`

A function to execute for each element in the typed array. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. 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 `some()` was called upon.


`thisArg` Optional

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

### Return value

`false` unless `callbackFn` returns a truthy value for a typed array element, in which case `true` is immediately returned.

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

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

Examples
--------

### Testing size of all typed array elements

The following example tests whether any element in the typed array is bigger than 10.


```js
function isBiggerThan10(element, index, array) {
  return element > 10;
}
new Uint8Array([2, 5, 8, 1, 4]).some(isBiggerThan10); // false
new Uint8Array([12, 5, 8, 1, 4]).some(isBiggerThan10); // true
```

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

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

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

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

See also
--------

* Polyfill of `TypedArray.prototype.some` in `core-js`
* JavaScript typed arrays guide
* `TypedArray`
* `TypedArray.prototype.every()`
* `TypedArray.prototype.forEach()`
* `TypedArray.prototype.find()`
* `TypedArray.prototype.includes()`
* `Array.prototype.some()`