Maybe this is a trivial problem, I do not know why this function exits the loop when it goes further. I need this function to get an XML document.
function xmlToArray(element){ childs= element.childNodes; if(childs.length != 1){ for(var i=0;i<childs.length;i++){ if(childs[i].hasChildNodes()){ xmlToArray(childs[i]); } alert("exit from if"); }//end for alert("exit from for"); }//end if else{ alert("do something with element"); } alert("end of func"); }
Since it is childsnot a local variable, all calls xmlToArraywork with the same data.
childs
xmlToArray
Try the following:
function xmlToArray(element) { var childs = element.childNodes; // … }
Usage vardeclares this variable in the current scope.
var
Source: https://habr.com/ru/post/1734588/More articles:Oracle Threads and Processes - oracleIMAP IDLE in Java - javaUnix system programming - unzipping a file programmatically - cРезультаты группы PHP/MySQL по столбцам - phpObject oriented beans and datamodel initialization? - javaMySQL - character order - sqlInstall drivers (WinUSB) with Clickonce? - clickonceC # - How to get a link to an object from a combo box? - c #VS2008 Non .NET Application - vb.netC ++ templated functor in lambda expression - c ++All Articles