Beginner here. So I was practicing using For loops to generate an array containing the combination of the data within 2 different arrays (firstName & lastName) into another array (fullNameArray) as shown below:
let firstName = ["John","Maria","Brandon","Gaby"];
let lastName = ["Stewart","Rambeau","Waffel","Sinclair"];
let fullNameArray=[];
function fullName (array1,array2){
let temp;
for (let i=0;i<array2.length;i++){
temp=array1[i]+" "+array2[i];
fullNameArray.push(temp);
};
};
fullName(firstName,lastName);
console.log(fullNameArray);
This code will give what i wanted : ['John Stewart','Maria Rambeau','Brandon Waffel','Gaby Sinclair']
But what i'm curious about is that i previously used return
inside the For loop. I wrote it like this:
function fullName (array1,array2){
let temp;
for (let i=0;i<array2.length;i++){
temp=array1[i]+" "+array2[i];
return fullNameArray.push(temp);
};
};
and it only shows ['John Stewart'].
Does this mean that using return
in a loop will terminate the ENTIRE looping process and go through it just once?