6/30/2023 0 Comments For of loop javascript![]() If you run the above code, you should have the following output: bread at 0 Normally with a for-of loop you get the element value and not the element index. ![]() The first and easiest way to get the index with a for-of loop is to use the Array's built in keys function, like this: for (const index of shoppingList.keys()) `) Let's start with the data that I will be using: const shoppingList = [ In this tutorial I will show you two ways that you can get the index when using a for-of loop.
0 Comments
Leave a Reply. |