Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Community Beginner ,
Oct 16, 2017 Oct 16, 2017

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?

TOPICS
Scripting
928
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Oct 16, 2017 Oct 16, 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 );

}

Translate
Advocate ,
Oct 16, 2017 Oct 16, 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 );

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 18, 2017 Oct 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 18, 2017 Oct 18, 2017
LATEST

Thanks for the explanation! It was misleading that my console printed something, so I believed it's a printed log, but it's clear now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines