Skip to content

Instantly share code, notes, and snippets.

@sumanssaurabh
Last active January 18, 2021 04:33
Show Gist options
  • Save sumanssaurabh/416eeaa879eafd16a0da6349b22b8865 to your computer and use it in GitHub Desktop.
Save sumanssaurabh/416eeaa879eafd16a0da6349b22b8865 to your computer and use it in GitHub Desktop.
iterate loop without for loop
const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
let counter = 0;
const len = arr.length;
const iterate = () => {
if (counter < len) {
console.log(arr[counter]);
counter = counter + 1;
iterate();
}
};
//invoke
iterate();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment