constarray=['one','two','three']// Array is a data source because it implements an iterator. console.log(typeofarray[Symbol.iterator])// function // We first get the iterator which allow us to iterate (i.e. consume) over the array values. constiterator=array[Symbol.iterator]()// The iterator follows the protocol of being an object with the 'next' function. console.log(typeofiterator.next)// function // Calling .next() returns the next element in the iteration. console.log(iterator.next())// { value: 'one', done: false } console.log(iterator.next())// { value: 'two', done: false } console.log(iterator.next())// { value: 'three', done: false } // Until there's no more elements to iterate, which then returns 'done' as true. iterator.next()// { value: undefined, done: true }
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Add js after 3 symbols to colr.