Why is JS doing this and what is it?

For some reason, my .splice returns something strange. Instead of returning the spliced item from an array, it returns something like a new array that is useless. Can anyone help me with this?
Screenshot_3 Screenshot_4


Without seeing the whole code, I’m taking a shot in the dark here. But… dl2 is a variable. Is the value of that variable, by chance, an HTML element?

It looks like it’s returning a collection of HTML elements, which in this case contains a single h2 element with the id of dl2.

1 Like

Yes, the value of dl2 is a <h1> element. My problem is that it’s not returning the value of dl2 like in the first console.log but this strange array

Ah, that would be because .splice() itself returns a new array containing the elements removed from the original array. :slight_smile:

1 Like

Is there any way that I could now edit the innerText of the h1 element?


The element dl2 is contained inside an array called nnn. Because it is the only item in the array, it is at index 0. You can access that element the same way you’d access any element in an array and use the .innerHTML method. :slight_smile:

1 Like

Thank you so much, I have been looking at this for hours!

1 Like

Glad I could help~! Happy Coding! :purple_heart:

1 Like