JavaScript | typedArray.values() with Examples

The typedArray.values() is an inbuilt function in JavaScript which is used to get specified value of the contents of the typedArray().

Syntax:

typedArray.values()

Parameters It does not accept any parameters.



Return value: It returns the specified value 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>
  
   // Constructing a new typedArray Uint8Array() with some value.
   const A = new Uint8Array([ 5, 10, 15, 20, 25, 30 ]);
  
   // Calling typedArray.values() function.
   const B = A.values();
  
   // Shifting array iterator to next element
   // iterator assigned to 10
   B.next();
     
   // iterator assigned to 15
   B.next();
     
   // iterator assigned to 20
   B.next();
  
   // Printing value 20 
   document.write(B.next().value);
     
</script>

chevron_right


Output:

20

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
   // Constructing a new typedArray Uint8Array() with some value.
   const A = new Uint8Array([5, 10, 15, 20, 25, 30]);
  
   // Calling typedArray.values() function.
   const B = A.values();
  
   // Shifting array iterator to next element
   // iterator assigned to 10
   B.next();
     
   // iterator assigned to 15
   B.next();
     
   // iterator assigned to 20
   B.next();
     
   // iterator assigned to 25
   B.next();
     
   // iterator assigned to 30
   B.next();
     
   // Now iterator go beyond the index
   B.next();
  
   document.write(B.next().value); 
     
</script>

chevron_right


Output:

undefined

Here output is undefined because the array iterator crosses 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.