Skip to content

Instantly share code, notes, and snippets.

@ooade
Created October 26, 2019 18:20
Show Gist options
  • Save ooade/1227f07841157370a8e22f31df0990b4 to your computer and use it in GitHub Desktop.
Save ooade/1227f07841157370a8e22f31df0990b4 to your computer and use it in GitHub Desktop.
Exactly like python's enumerate function
let enumerate = string => string.split('').map((v, i) => [i, v]);
@ooade
Copy link
Author

ooade commented Oct 26, 2019

To be used with for..of like:

const name = 'Ademola';

for ([index, letter] of enumerate(name)) {
   console.log(`The index of ${letter} is ${index}`);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment