JavaScript | typedArray.@@iterator with Example

The typedArray.@@iterator is an inbuilt property in JavaScript which is used to return the initial value of the given typedArray’s element.
Syntax:

arr[Symbol.iterator]()

Parameters: It does not accept any parameter because it is a property not a function.
Return value: It returns the array iterator function i.e, values() function by default.
JavaScript code to show the working of this property:

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
  
    // Constructing a new typedArray with some elements
    var A = new Uint8Array([ 5, 10, 15, 20, 25 ]);
  
   // Calling iterator() function
    var a = A[Symbol.iterator]();
  
    // Printing each value of the typedArray
    document.write(a.next().value + "<br>");
    document.write(a.next().value + "<br>");
    document.write(a.next().value + "<br>");
    document.write(a.next().value + "<br>");
    document.write(a.next().value);
  
</script>

chevron_right


Output:

5
10
15
20
25


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.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.