I don’t know whats wrong with this:
var get_depth = function(item, depth) {
if(item.parent_id !== null) {
get_depth(get_item_by_id(item.parent_id),depth+1);
} else {
alert ("return: " + depth);
return depth;
}
};
The alert message always throws a correct depth but the variable where i want to have the value stored in only accept one iteration (return value = 1) after two or more iterations the value of my variable is undefined. I do not understand that.
That’s because you should return the value each time :