Skip to main content
Participant
October 16, 2017
Answered

AE's Script Editor logs only the last object in for loop

  • October 16, 2017
  • 1 reply
  • 919 views

When I call the following in AE's Script Editor:

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

Only the third (last) object is printed in the consol. Is this normal? I mean the whole script runs but only the last object is printed? I would really appreciate if somebody could explain me why don't

a

b

c

is printed.

Is it something that can be adjusted somewhere in the settings?

This topic has been closed for replies.
Correct answer Tomas Sinkunas

Actually, in your code you are printing nothing to console. You are just looping through an array. The following method prints on every iteration.

var arr = [ "a", "b", "c" ];

for(var i=0; i < arr.length; i++) {

  $.write( arr );

}

1 reply

Tomas Sinkunas
Tomas SinkunasCorrect answer
Legend
October 17, 2017

Actually, in your code you are printing nothing to console. You are just looping through an array. The following method prints on every iteration.

var arr = [ "a", "b", "c" ];

for(var i=0; i < arr.length; i++) {

  $.write( arr );

}

Mathias Moehl
Community Expert
Community Expert
October 18, 2017

Tomas is right. When you execute a script, its result is simply the value of the last statement that is evaluated. If you want to log intermediate results, you can use $.write.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects