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

96
Vistas
Problem removing the last element from an array

N.B. I am a complete JavaScript beginner.

My assignment is to create an empty array and assign it to a variable. Then, using a for loop, place the numbers 0 to 5 into the array. Then I need to remove the last number in the array and console.log the result. Any thoughts on why .pop() isn't working? It works when I use it on an array that I construct without a for loop. Thanks.

var numberList = new Array();
for (let numberList = 0; numberList < 6 ; numberList++)
console.log(numberList);
numberList.pop();
console.log(numberList);

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You're not pushing anything into the array. Right now, all you do is writing to the console. You need to use Array.push(). Also, you overwrite the numberList array with an integer in your for loop.

var numberList = new Array();

for (let i = 0; i < 6 ; i++) {
  numberList.push(i);
}

console.log(numberList);
numberList.pop();
console.log(numberList);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You did not add any elements to the array. Use Array#push to do so.

let numberList = new Array();
for (let i = 0; i < 6 ; i++) numberList.push(i);
console.log(...numberList);
numberList.pop();
console.log(...numberList);

about 4 years ago · Juan Pablo Isaza Denunciar

0

There are multiple issues in the code.

var numberList = new Array();
for (let index= 0; index< 6 ; index++){
    numberList.push(index);
}
console.log(numberList);
numberList.pop();
console.log(numberList);
about 4 years ago · Juan Pablo Isaza Denunciar
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