Is there a way to determine if an array contains empty elements? Consider the following array:
var arr = [ 'a', 'b', , 'd'];
In this case, arr[2] is undefined
. It's important to check for such occurrences. One approach could be like this:
function hasEmptyElement(array){
for (var i=0; i<array.length; i++){
if (typeof arr[i] == 'undefined'){
return true;
// What should be done next?
// Should I consider using nested loops or a helper variable?
}
}
}
I'm unsure about the best solution for this problem. Any clever ideas would be greatly appreciated.