Advertisement
goodwin64

Making Number iterable

Feb 20th, 2023
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Number.prototype[Symbol.iterator] = function() {
  2.     let iterValue = 0;
  3.     const finalValue = this.valueOf();
  4.     return {
  5.         next: () => ({
  6.             done: iterValue === finalValue,
  7.             value: iterValue++,
  8.         }),
  9.     }
  10. }
  11.  
  12. console.log([...8]);
  13. // >>>Β [0, 1, 2, 3, 4, 5, 6, 7]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement