For Loop III - Nested Loop

Nested Loop means one or more loops can be placed inside of another loop.

Code Structure
var firstNames = ["Jessica", "Brad", "Jackie", "Arnold", "Rocky"];
var lastNames = ["Alba", "Pitt", "Chan"];
var fullNames = [];
for(var i = 0; i < firstNames.length; i++){
 for(var j = 0; j < lastNames.length; j++) {
  fullNames.push(firstNames[i] + lastNames[j]);
  alert(fullNames);
 }
}

Share this

Related Posts