DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on

Use an array as an iterable

const arr = [1, 2];

console.log(arr.next()); // Error

const iterable = arr.values();
console.log(iterable.next()); // { value: 1, done: false }
console.log(iterable.next()); // { value: 2, done: false }
console.log(iterable.next()); // { value: undefined, done: true }
Enter fullscreen mode Exit fullscreen mode

Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Top comments (0)