querySelectorAll(selectors)
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>NodeList</title>
    </head>
    <body>
        <ul>
            <li>Pizza</li>
            <li>Burger</li>
            <li>Pasta</li>
        </ul>
        <script src="queryselectorall.js"></script>
    </body>
</html>
const liElements = document.querySelectorAll("li"); // Select all <li> elements
console.log(liElements); // NodeList(3) [li, li, li]

/* Method 1 - Using for...of loop */
for (const liElement of liElements) {
    console.log(liElement.textContent);
}
// Output: "Pizza" "Burger" "Pasta"

/* Method 2 - Using for loop */
for (let i = 0; i < liElements.length; i++) {
    console.log(liElements[i].textContent);
}
// Output: "Pizza" "Burger" "Pasta"

/* Method 3 - Using forEach() method */
liElements.forEach(li => { // Although it is array-like, forEach() can be used
    console.log(li.textContent);
});
// Output: "Pizza" "Burger" "Pasta"
// Select an HTML element
const myElement = document.getElementById("myElement");

// Get the list of child nodes of myElement
const childNodes = myElement.childNodes;

// Iterate through the child nodes and print them
for (var i = 0; i < childNodes.length; i++) {
    console.log(childNodes[i]);
}
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>NodeList</title>     
    </head>
    <body>
        <ul id="list">
            <li>Pizza</li>
            <li>Burger</li>
            <li>Pasta</li>
        </ul>
        <p><code><li></code> element count: <strong id="li-length-val">3</strong></p>
        <button type="button" id="addButton">Add New Menu</button>
        <script src="none-live.js"></script>
    </body>
</html>
// Get the NodeList
const liElements = document.querySelectorAll("li");

// Add a new <li> element when the button is clicked
document.getElementById('addButton').addEventListener("click", () => {
    const newLi = document.createElement("li");
    newLi.textContent = "New Menu Item";

    // Add the new <li> element to the <ul>
    document.getElementById("list").appendChild(newLi);

    // Check the number of <li> elements in real-time
    const liElementsLength = liElements.length; // liElements length is not updated in real-time
    document.getElementById("li-length-val").textContent = liElementsLength;
});
Live Demo