Tutorialspoint.dev

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:



<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>

/div>

Output:

20

Code #2:

<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>

Output:

undefined

Here output is undefined because the array iterator crosses the upper bound.



This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter