To convert an array to an iterator in JavaScript, you can use the “Symbol.iterator” property.
Arrays implement the iterable protocol, meaning they have a built-in Symbol.iterator property that returns an iterator object.
const mainArray = [11, 21, 19, 46, 18];
const iterator = mainArray[Symbol.iterator]();
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
console.log(iterator.next());
Output
{ value: 11, done: false }
{ value: 21, done: false }
{ value: 19, done: false }
{ value: 46, done: false }
{ value: 18, done: false }
In this code, we have an array called mainArray.
We used the “Symbol.iterator” property of the array to create an iterator called an iterator.
In the next step, we called the “next()” method of the iterator to get the next value in the array.
The “next()” method returns an object with two properties: value, the current value in the array, and, done, a boolean value suggesting whether the iteration is complete.
The output of the “console.log()” statements demonstrates the iteration process.

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.