Search code examples
javascriptafter-effects

The console of After Effects's Script Editor logs only the last object in for loop


I have the following for loop:

var arr = [ "a", "b", "c" ];
for(var i=0; i < arr.length; i++) {
    arr[i];
}

When I call it in the Script Editor of After Effects CC 2014 only c will be printed in the console instead of:

a
b
c

Is this normal that only the last object of the Array is printed? What happens in the background? The loop runs normally like a then b then c and printing the last object only is just an option of the Script Editor?


Solution

  • Is this normal that only the last object of the Array is printed?

    Yes this is normal behaviour for ExtendScript Toolkit (ESTK),

    What happens in the background?

    I loops through your array.

    The loop runs normally like a then b then c and printing the last object only is just an option of the Script Editor?

    Yes. Again.

    If you want to print out things you need to use $.write() or $.writeln(). This will be visible in the ESTK console. You can find the more on the $ helper object in the ESTK under "Help>Javacript Tools Guide CC".