I am trying to understand why the code below does not seem to be returning retVal to the calling function>
The called function is
function GetDropDownItems(pDropDowns, pDropDownTarget) { retVal = null; pDropDowns.forEach(dropDown => { r = dropDown.querySelector('div[aria-labelledby="' + pDropDownTarget + '"]'); if (r != null) { retVal = Array.from(r.querySelectorAll('a.dropdown-item')); console.log('GetDropDownItems ', retVal); return retVal; } }); }
The calling function is:
function GetNavData() { menuItems = null; . . . switch (title) { case 'inventory home': menuItems = GetDropDownItems(dropDowns, 'InventoryMenu'); console.log('GetNavData ', menuItems); return menuItems; break; } }
Abbreviated the code in calling function down to just point value is returned.
When the code is run and I look at the console in the browser the line
console.log('GetDropDownItems ', retVal);
Shows that retVal has the data that is expected.
However, the lines below in the calling function show menuItems as undefined.
menuItems = GetDropDownItems(dropDowns, 'InventoryMenu');
console.log('GetNavData ', menuItems);