JavaScript TypedArray entries() Method - JavaScript Tutorial

JavaScript TypedArray entries() Method

BLUF: This tutorial on JavaScript TypedArray entries() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript TypedArray entries() Method

Understanding JavaScript TypedArray entries() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

This technique produces a fresh Array Iterator object that holds key/value pairs corresponding to each index within the array. For every element in the initial array, the newly created iterator object will consist of an array where the index serves as the key and the element acts as the value.

What is Iterator?

An iterator is an object that maintains its current position as it sequentially accesses elements within a collection, one at a time.

An iterator provides an object that contains two attributes: key and value.

Syntax:

Example

array.entries ()

Parameters:

No parameters.

Return value:

A new Array Iterator object.

Browser Support:

Chrome 38
Edge Yes
Firefox 28
Opera No

Example 1

Example

<script type="text/javascript">

// JavaScript to illustrate entries() method

 var array1 = ["Example","Core java","Advanced java"];





var iterator1 = array1.entries();





document.write(iterator1.next().value);



document.write("<br>")

// expected output: Array [0, "Example"]





document.write(iterator1.next().value);

// expected output: Array [1, "Core java"]



</script>

Output:

Output

[0, 'Example']

[1,'Core java']

Example 2

Example

<script type="text/javascript">

// JavaScript to illustrate entries() method

// Input array

var a = ['Core Java', 'Python', 'Android'];

var iterator = a.entries();

for (let e of iterator) {

document.write("<br>") 

document.write(e);

}

// expected output

// [0, 'core Java']

// [1, 'Python']

// [2, 'Android'] 

</script>

Output:

Output

[0, 'core Java']

 [1, 'Python']

[2, 'Android']

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience