I have a recursive function that loops over elements, i want to console log the json object once the recursive function has completed. would this be best with a promise or callback?
here is my current code
function productData(elem) {
    if(elem.hasAttribute("itemprop")) {
      const itemProp =  elem.getAttribute("itemprop");
      const itemText = elem.innerText;
      items[itemProp] = itemText;
      console.log("items", items);
    }
    if (elem.hasChildNodes()) {
      Array.from(elem.children).forEach(function (item) {
        productData(item);
      });
    }
  }
  const items = {}
  // Get All Products on the page
  const product = document.querySelectorAll('[itemtype="http://schema.org/Product"]');
  productData(product[0])
 
     
    