JavaScript TypedArray keys() Method - JavaScript Tutorial

JavaScript TypedArray keys() Method

BLUF: This tutorial on JavaScript TypedArray keys() 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 keys() Method

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

The keys method in JavaScript is a built-in function. This method produces an Array Iterator object that contains the keys of an array.

What is Iterator?

An iterator is a construct that monitors its current position as it retrieves items from a collection sequentially, one at a time.

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

Syntax:

Example

array.keys()

Parameters:

No parameters.

Return value:

It produces a fresh array iterator instance that includes the keys corresponding to each index of the elements within the specified array.

Browser Support:

Chrome 38.0
Edge 8
Firefox 28.0
Opera 25.0

Example

JavaScript TypedArray keys Method

Example

<script type="text/javascript">

// JavaScript to illustrate keys() method

// Creating some typedArrays

  var A = new Uint8Array([1, 2, 3, 4, 5]);

  var B = new Uint8Array([5, 10, 15, 20]);

 



   a = A.keys()

   document.write(a.next().value +"<br>");

    

   b = B.keys()

   b.next();

   document.write(b.next().value +"<br>");

   // expected output: arr[Output:0 1]

     

</script>

Output:

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