Enumerate method

  • Unlike Python, which need to use enumerate, Javascript have this functionality built-in. For example, there is a method which is extremely useful in Javascript called forEach.

fruits = ["apple", "watermelon", "lemon"]
fruits.forEach((fruit, index) => console.log(fruit, index))
Note that we didn't need to use anything like enumerate here.

Last updated