CodesJava

Easy learning with example program codes

TypedArray Keys() JavaScript

The Javascript TypedArray Keys() method is used to retrieve an Array Iterator object with the keys of an array.

Syntax:

array.keys()  

Parameters:
value: It represents the current element’s value.
index: It represents the index position of current element.
arr: It represents the array.
thisValue: It represents this argument for the function.

Returns:
It returns an iterator object containing the keys as index for each array element.

Example 1:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">   
var Jewels = ["DIAMOND","GOLD","PLATINUM","SILVER"];
result = Jewels.keys()  
document.write(result.next().value +"<br>");  
document.write(result.next().value +"<br>");
document.write(result.next().value +"<br>");
document.write(result.next().value);  
</script>
</body>
</html>

Output:

0
1
2
3

Example 2:

<!DOCTYPE html>
<html>
<body>
<script type="text/javascript"> 
var arr = new Uint8Array([34, 12, 45, 78, 12]);
var arrKey = arr.keys();
 
for (let key of arrKey) {
  document.write(key);
  document.write("</br>");
}
 
</script>
</body>
</html>

Output:

0
1
2
3
4
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status