This solution is generated by ChatGPT, correctness is not guaranteed. You might also be able to find a solution fromcommunity posts.
AI solution for Interview Question on BFE.dev
59. What is Array-Like Objects in JavaScript?
An Array-Like object is an object that has properties and methods similar to a regular Array object but does not possess all the functionalities of a regular array, such as the methods like push()
, pop()
, and splice()
. These objects can be indexed like an array, and their property values can be accessed with bracket notation.
To loop through Array-Like Objects, we can use a for loop or forEach method, just like we do for regular arrays. Here is an example of using a for loop to loop through a NodeList object:
const list = document.querySelectorAll('li');
for (let i = 0; i < list.length; i++) {
console.log(list[i].textContent);
}