Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
Does Return terminates a Loop entirely before it finishes?

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!