JavaScript | typedArray.entries() with Examples

The typedArray.entries() is an inbuilt function in JavaScript which 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 code to show the working of this function:

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Creating a typedArray Uint8Array() with some elements
    const uint8 = new Uint8Array([ 5, 10, 15, 20, 25, 30 ]);
  
    // Calling entries() function
    A = uint8.entries();
  
    // Shifting array iterator to next element one by one
    // Iterator assigned to 10
    A.next();
      
    // Iterator assigned to 15
    A.next();
      
    document.write(A.next().value);
  
</script>

chevron_right


Output:



2, 15

Here 2 is the index of element 15.
Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Creating a typedArray Uint8Array() with some elements
    const uint8 = new Uint8Array([ 5, 10, 15, 20, 25 ]);
  
   // Calling entries() function
   A = uint8.entries();
  
   // Shifting array iterator to next element one by one
   // Iterator assigned to 10
   A.next();
     
   // Iterator assigned to 15
   A.next();
     
   // Iterator assigned to 20
   A.next();
     
   // Iterator assigned to 25
   A.next();
     
   // Iterator went out of index
   A.next();
   document.write(A.next().value);
     
</script>

chevron_right


Output:

undefined

Here output is undefined because iterator exceeds the upper bound.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.