Loops in JavaScript are used to iterate a piece of code. In simple words, Loops are used to execute any block of code again and again until certain conditions are fulfilled. There are major 3 types of loop in JavaScript, For loop, While loop and Do-While loop. For Loop In for loop…