The entries() function of TypedArray returns an iterator of the corresponding TypedArray object and using this, you can retrieve the key-value pairs of it. Where it returns the index of the array and the element in that particular index.
Syntax
Its Syntax is as follows
typedArray.entries()
Example
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]); document.write("Contents of the typed array: "+int32View); document.write("<br>"); var it = int32View.entries(); for(i=0; i<int32View.length; i++) { document.write(it.next().value); document.write("<br>"); } </script> </body> </html>
Output
Contents of the typed array: 21,64,89,65,33,66,87,55 0,21 1,64 2,89 3,65 4,33 5,66 6,87 7,55
Example
If you try to access the next element of the array when the iterator points to the end of the array you will get undefined as result.
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55]); document.write("Contents of the typed array: "+int32View); document.write("<br>"); var it = int32View.entries(); for(i=0; i<int32View.length; i++) { document.write(it.next().value); document.write("<br>"); } document.write(it.next().value); </script> </body> </html>
Output
Contents of the typed array: 21,64,89,65,33,66,87,55 0,21 1,64 2,89 3,65 4,33 5,66 6,87 7,55 undefined