Typed Array keys()
Example
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// Create an Iterable Array of the Keys
const list = myArr.keys();
// List the Keys
let text = "";
for (let x of list) {
text += x + "<br>";
}
Try it Yourself »
More Examples Below !
Description
The keys()
method returns an iterator with the keys of a typed array.
The keys()
method does not change the original typed array.
Typed Array Iteration Methods:
Syntax
typed-array.keys()
Parameters
NONE |
Return Value
Type | Description |
Iterator | An Array Iterator object containing the keys of the typed array. |
More Examples
Example
Iterate directly over the iterator:
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// List the Keys
let text = "";
for (let x of myArr.keys()) {
text += x + "<br>";
}
Try it Yourself »
Example
Use the built in Object.keys() method:
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// List the Keys
let text = "";
for (let x of Object.keys(myArr)) {
text += x + "<br>";
}
Try it Yourself »
JavaScript Typed Arrays
Browser Support
type-array.keys()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |