Basic JavaScript - Iterate with JavaScript While Loops

Hello I wanted to know why can’t I use the pop function if it’s to remove?

// Setup
const myArray = []

// Only change code below this line
let i = 5;
while (i >= 0){
  myArray.pop(i);
  i--;
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Iterate with JavaScript While Loops

Link to the challenge:

Add the numbers 5 through 0 (inclusive) in descending order to myArray using a while loop.

The Challenge wants you to add elements to the array but pop removes elements.

2 Likes

ahh makes sense haha thanks!!!

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.