I've created a function that loops through one array, using each value (item) to check whether a different value (clicked_item) exists in an array called item.
This works great. In the log statement, it correctly identifies the parent (item) and the type (string). Output in console: FOUND PARENT FOR: pinot-noir-gifts IT IS ITEM: red_wine_gifts TYPE: string
However return item returns undefined when it should return red_wine_gifts. The result is that clicked_item_parent is undefined.
Why would the script be able to log a value but the function returns it as undefined?
function find_parent(clicked_item)
{
filter_have_children.forEach( function(item){
var look_here = filter_children[item];
if ( look_here.indexOf(clicked_item) != "-1" )
{
console.log("FOUND PARENT FOR: "+clicked_item+" IT IS ITEM: "+item+" TYPE: "+typeof item);
return item;
}
});
}
var clicked_item_parent = find_parent(clicked_item);
if ( typeof clicked_item_parent !== "undefined" )
{
// Do some things
}
else console.log("parent was undefined");