Typed Array entries()
Example
// Create a Typed Array
const myArr = Int32Array.of(10,20,30,40,50,60);
const myIterator = myArr.entries();
// List the Entries
let text = "";
for (let x of myIterator) {
text += x;
}
Try it Yourself »
More Examples Below!
Description
The entries()
method returns an Iterator object with the key/value pairs from an array.
The entries()
method does not change the original array.
Syntax
typed-array.entries()
typed-array must be one of the following: Int8ArrayUint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float16Array Float32Array Float64Array BigInt64Array BigUint64Array |
Parameters
NONE |
Return Value
Type | Description |
Iterable | An Iterable object with the key/value pairs from the typed array. |
More Examples
Example
Iterate directly over the Iterator:
// Create a Typed Array
const myArr = Int32Array.of(10,20,30,40,50,60);
// List the Entries
let text = "";
for (let x of myArr.entries()) {
text += x;
}
Try it Yourself »
Example
Use the built in Object.entries() method:
// Create a Typed Array
const myArr = Int32Array.of(10,20,30,40,50,60);
// List the Entries
let text = "";
for (let x of Object.entries(myArr)) {
text += x;
}
Try it Yourself »
Note
It is not a good practice to save an iterator.
The iterator has a next() method to access each element one at a time.
As soon as you start using it, it cannot be reset or restarted.
Example
Use the next() method of the iterator:
// Create a Typed Array
const myArr = Int32Array.of(10,20,30,40,50,60);
// Create an Interator
const myIterator = fruits.entries();
// List the entries
let text = myIterator.next().value + " " + myIterator.next().value;
Try it Yourself »
JavaScript Typed Arrays
Browser Support
entries()
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 |
entries()
is not supported in Internet Explorer.