logo CodeStepByStep logo

arrayMystery3

Language/Type: JavaScript arrays array mystery

What are the contents of the array arr after the following code executes?

let arr = [];
for (let i = 1; i <= 5; i++) {
    arr.push(2 * i);         // [2, 4, 6, 8, 10]
}
let size = arr.length;
for (let i = 0; i < size; i++) {
    arr.splice(i, 0, 42);   // add 42 at index i
}
contents of arr

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.