Related Articles

Related Articles

JavaScript | typedArray.keys() with Example
  • Last Updated : 24 Jul, 2018

The typedArray.keys() is an inbuilt function in JavaScript which is used to return a new array iterator containing the keys for each index of the elements of the given typedArray.
Syntax:

typedArray.keys()

Parameter: This function does not accept anything as parameter.
Return value: It returns a new array iterator object containing the keys for each index of the elements of the given typedArray.
JavaScript code to show the working of this function:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
  // Creating some typedArrays
  const A = new Uint8Array([1, 2, 3, 4, 5]);
  const B = new Uint8Array([5, 10, 15, 20]);
  const C = new Uint8Array([0, 2, 4, 6, ,8, 10]);
  const D = new Uint8Array([1, 3, 5, 7, 9]);
   
   // Calling keys() function
   a = A.keys()
   document.write(a.next().value +"<br>");
     
   b = B.keys()
   b.next();
   document.write(b.next().value +"<br>");
     
   c = C.keys()
   c.next();
   c.next();
   document.write(c.next().value +"<br>");
     
   d = D.keys()
   d.next();
   d.next();
   d.next();
   document.write(d.next().value +"<br>");
      
</script>

chevron_right


Output:

0
1
2
3

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :