开发者

add variable to array in a loop

开发者 https://www.devze.com 2023-04-10 01:43 出处:网络
using extend script to push a variable into an array it\'s basically javascript. any idea what I am doing wrong?

using extend script to push a variable into an array it's basically javascript. any idea what I am doing wrong?

if ( app.documents.length > 0 ) {

    for ( i = 0; i< app.activeDocument.textFrames.length; i++) {
    开发者_运维知识库     var allSizes = []; //set up empty array

        textArtRange = app.activeDocument.textFrames[i].textRange;
        var fontName =  textFonts.getByName("Nobile");
        alert (fontName);
        textArtRange.characterAttributes.textFont = fontName;
        var fontSizes = textArtRange.characterAttributes.size;

        allSizes.push(fontSizes)
        alert (fontSizes);

    }
        alert (allSizes);
}

the alerts for allSizes only return single values, not the array.


Move the definition of allSizes = [] outside the loop.

Currently, you're "resetting" the value of allSizes at each loop.


You're setting up the empty array inside of the for loop. It's resetting it each time. Move it above the for loop:

var allSizes = []; //set up empty array
for ( i = 0; i< app.activeDocument.textFrames.length; i++) {
     .....
0

精彩评论

暂无评论...
验证码 换一张
取 消