Why don't this code remove the last paragraph element from div? [SOLVED] | SoloLearn: Learn to code for FREE!

+3

Why don't this code remove the last paragraph element from div? [SOLVED]

https://code.sololearn.com/WREl95FO1zn5/?ref=app

6/3/2020 7:04:27 PM

Abhay

5 Answers

New Answer

+4

I think I got it ,when first element is removed ,f length gets reduced to 1 from 2 and since the next element to be removed is at index 1 the only element left in f array is at index 0

+2

Abhay If you haven't already, replace the children with these <p>0</p> <p>1</p> <p>2</p> <p>3</p> <p>4</p> <p>5</p>

+2

So it removes the element at even indexes ,how is that even possible? Isn't for loop used to iterate through every element in array

+2

A little visual https://code.sololearn.com/Wg5TJKC4k4NV/#html

+2

ODLNT nice one,ty:-)