i have an array i’m trying to loop through by array.length but it stops in the middle of the loop for no reason.
code :
var id = ['88' , '89' , '90' , '91' , '92' , '93' , '94' , '95' , '96' , '97' , '98' ];
var parent_id = ['1' , '1' , '88' , '1' , '88' , '91' , '93' , '93' , '92' , '90' , '97' ];
function getAllLearningPaths(id){
document.getElementById("catdiv").innerHTML += "THIS IS HE CURRENT CATEGORY ID : " + id + "<br>";
for(var i=0; i < id.length;i++)
{
document.getElementById("catdiv").innerHTML += "THIS IS HE CURRENT CATEGORY PARENT ID : " + parent_id[i] + "<br>";
if(parent_id[i] == id && id[i] != id)
{
document.getElementById("catdiv").innerHTML += "I MADE IT!";
getAllLearningPaths(parent_id[i]);
}
}
for(var i=0; i< Categories.length;i++)
{
if(Categories[i] == id)
{
document.getElementById("l_ids_"+CategoriesValues[i]).checked = true;
disablerow(document.getElementById("l_ids_"+CategoriesValues[i]), '1');
}
}
return;
}
categories is populated somewhere else in the code. it’s no problem.
the thing is that the first loop dosen’t pass the 2nd run.
this code outputs :
THIS IS HE CURRENT CATEGORY ID : 88
THIS IS HE CURRENT CATEGORY PARENT ID : 1
THIS IS HE CURRENT CATEGORY PARENT ID : 1
any idea?
This line looks wrong –
parent_idlooks like an array of ints so theidvariable would need to be an int to pass this test. You then refer toias an array in the next part of the if statement –id[i] != id.