I have an array of arrays and some of the inner arrays have yet another nested array. Some don't. I loop through the top level array elements and IF there is an internal array I loop through them. If there isn't one, I don't. Or so I think.
for some reason when my iteration finds an array without a nested array my console shows "type error" undefined... which is technically right as there is no nested array defined. However I thought my nested if statement wouldn't allow this to be evaulated. Any thoughts?
for example animation[0][3] is an array but animations[1][3] is undefined. so in my if loop i have a nested
var a = animations.shift();
if ( a[3] )
{
console.log( 'a[3] is: ' + a[3] )
}
else
{
return;
}
I read that as, if a[3] exists log it to console, if not escape without printing to console... yet my console continues to produce an undefined evaluation. Is that because simply testing for it's existence returns an undefined error? How do I stop this error from popping up every time i run into an array that does not have a nested array?
Thanks.
var animations = [
['.pcba','fadeIn', [1000], [
['.pcb_cad', 'fadeIn', [1000] ]
]
],
['.pcba', 'delay', [2000] ],
['.pcba','fadeOut', [1000], [
['.heatGenComps', 'fadeIn', [1000] ],
['.arrows', 'fadeIn', [1000] ]
]
],
['.heatGenComps', 'delay', [2000] ],
['.heatGenComps', 'fadeOut', [1000], [
['.arrows', 'fadeOut', [1000] ],
['.pcb_cad_cfd', 'fadeIn', [1000] ],
['.wePredOpTemps', 'fadeIn', [1000] ]
]
],
];
and I iterate through them like:
iter();
function iter(){
if (!animating) return;
var a = animations.shift();
if (a) {
var el = a[0];
var fn = a[1];
var args = a[2];
$.fn[ a[1] ].apply( $( a[0] ), a[2] ).promise().done(iter);
if ( a[3] )
{
var secondary = a[3];
console.log( 'a[3] is: ' + a[3] );
secondaryAnime();
function secondaryAnime(){
b = secondary.shift();
console.log('secondary is: ' + b );
$.fn[ b[1] ].apply( $( b[0] ), b[2] );
secondaryAnime();
};
}
else
{
return;
}
}
else
{
}
};