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

98
Views
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 answers
Answer question

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 Report

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 Report

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 Report
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!