1

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?

mesqueeb
  • 5,277
  • 5
  • 44
  • 77

1 Answers1

4

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);
jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • @mesqueeb - Did this answer your question? If so, you could indicate that to the community here by clicking the checkmark to the left of the answer and that will also earn you some reputation points here for following the proper procedure. – jfriend00 Mar 03 '21 at 04:04