admin管理员组文章数量:1192918
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.
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.
Share Improve this question asked Oct 3, 2011 at 17:45 LukaszLukasz 9463 gold badges14 silver badges22 bronze badges 02 Answers
Reset to default 13Move 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++) {
.....
本文标签: javascriptadd variable to array in a loopStack Overflow
版权声明:本文标题:javascript - add variable to array in a loop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738467955a2088412.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论