Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda