Friday, November 21, 2025
HomeLanguagesJavascriptJavaScript typedArray.entries() with Examples

JavaScript typedArray.entries() with Examples

The Javascript typedArray.entries() is an inbuilt function in JavaScript that gives a new array iterator object containing the key and value pairs of the given typedArray object. 

Syntax:

typedArray.entries()

Parameter: It does not accept any parameters. 

Return value It returns a new array iterator object containing the key and value pairs of the given typedArray object.

JavaScript examples to show the working of this function:

Example 1: In this example, we will use the typedArray.entries() function to return the key and value pairs of the object.

javascript




<script>
    // Creating a typedArray Uint8Array() with some elements
    const uint8 = new Uint8Array([ 5, 10, 15, 20, 25, 30 ]);
      
    // Calling entries() function
    A = uint8.entries();
      
    // Shifting array iterator to next element one by one
    // Iterator assigned to 10
    A.next();
      
    // Iterator assigned to 15
    A.next();
      
    console.log(A.next().value);
</script>


Output: Here 2 is the index of element 15.

2, 15

 Example 2: Here output is undefined because iterator exceeds the upper bound.

javascript




<script>
    // Creating a typedArray Uint8Array() with some elements
    const uint8 = new Uint8Array([ 5, 10, 15, 20, 25 ]);
      
    // Calling entries() function
    A = uint8.entries();
      
    // Shifting array iterator to next element one by one
    // Iterator assigned to 10
    A.next();
      
    // Iterator assigned to 15
    A.next();
      
    // Iterator assigned to 20
    A.next();
      
    // Iterator assigned to 25
    A.next();
      
    // Iterator went out of index
    A.next();
    console.log(A.next().value);
</script>


Output:

undefined
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6781 POSTS0 COMMENTS
Nicole Veronica
11928 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6907 POSTS0 COMMENTS
Ted Musemwa
7166 POSTS0 COMMENTS
Thapelo Manthata
6862 POSTS0 COMMENTS
Umr Jansen
6847 POSTS0 COMMENTS