2

I have found the answer to: Convert ES6 Iterable to Array

But I'm looking for the opposite:

How can I convert an Array like ['something', 'another thing'] to an ES6 Iterable?

0

1 Answer 1

5

An Array already is an ES6 iterable.

"Iterable" is a capability that a number of different types of objects can have and an Array has that capability built-in (as of ES6).

For example, you can directly use the iterator capabilities with something like:

for (let item of ['something', 'another thing']) {
     console.log(item);
}

Or, you could directly get the iterator with this:

const myIterator = ['something', 'another thing'].entries();
console.log(myIterator.next().value);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.