Iterables

The iterable is a interface that specifies that an object can be accessible if it implements a method who is key is [symbol.iterator].

Some of the built-in data structure that use iterable are :

Arrays

Strings

Maps

Sets etc.

Why iterable were added in ES6?

Without iterable, it is difficult to manage the iteration on data for various types of data structures i.e iterating on an array is different from iterating on an object.

Also, ES6 has introduced new data structures like sets and maps so it will become more complicated to write logic as per data structure for iterations.

This is where the iterable interface was born.

There are two things to notice here