if(childrens are present) {
while(childrens.length ! ==0) {
do something
}
}
// Execute this function fnName()
My problem here is the while condition is getting executed, but when the length becomes zero… it does not come out… and execute the fnName()
If you’re actually removing children from the array in the loop, that should be fine other than that you’ve got the spacing wrong on the operator; it should be
!==, not! ==:Note that to actually remove children from the array, you have to use one of the array mutator methods, like
poporsplice. My guess is that you’re not doing that.The more normal thing to do would be to loop through the array without mutating it:
Or using the new ES5 stuff like
forEach(which requires knowing your users will have a very up-to-date browser, or including an “ES5 shim” sinceforEachis one of the things that can be shimmed):Side note: The word “children” is already a plural (the singular is “child”), so there’s no “s” on the end of it. Just one of English’s irregular plurals (there are several).