JavaScript typedArray.entries() with Examples
The Javascript typedArray.entries() is an inbuilt function in JavaScript that gives a new array iterator object containing the key and value pairs of the given typedArray object.
Syntax:
typedArray.entries()
Parameter: It does not accept any parameters.
Return value It returns a new array iterator object containing the key and value pairs of the given typedArray object.
JavaScript examples to show the working of this function:
Example 1: In this example, we will use the typedArray.entries() function to return the key and value pairs of the object.
javascript
<script>
const uint8 = new Uint8Array([ 5, 10, 15, 20, 25, 30 ]);
A = uint8.entries();
A.next();
A.next();
console.log(A.next().value);
</script>
|
Output: Here 2 is the index of element 15.
2, 15
Example 2: Here output is undefined because iterator exceeds the upper bound.
javascript
<script>
const uint8 = new Uint8Array([ 5, 10, 15, 20, 25 ]);
A = uint8.entries();
A.next();
A.next();
A.next();
A.next();
A.next();
console.log(A.next().value);
</script>
|
Output:
undefined
Last Updated :
22 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...