For-loop is used when you want to execute a block of code repeatedly for a particular amount of time.
Let’s consider an example, suppose you want to print “hello world” 5 times, what we will do is write console.log(“hello world”) five times.
Instead what we can do is used a for loop for same the with less effort, here’s how :
Let’s us see an example that will clear your doubt:
1 : apple
2 : banana
Here, “I” represents the keys of the object and fruits[i] represent respective key values.
This loop can be used over array, maps, sets, objects, strings and more, this loop was introduced in ECMA script 6 (ES6), it is like the simple version of the general for-loop, it iterates through all the iterables present in the iterable.
You will understand easily with a simple example below: