Why don't this code remove the last paragraph element from div? [SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

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

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

3rd Jun 2020, 7:04 PM
Abhay
Abhay - avatar
5 Answers
+ 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
3rd Jun 2020, 8:12 PM
Abhay
Abhay - avatar
+ 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>
3rd Jun 2020, 7:25 PM
ODLNT
ODLNT - avatar
+ 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
3rd Jun 2020, 7:44 PM
Abhay
Abhay - avatar
3rd Jun 2020, 9:15 PM
ODLNT
ODLNT - avatar
+ 2
ODLNT nice one,ty:-)
3rd Jun 2020, 10:25 PM
Abhay
Abhay - avatar