ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Is it possible to add the values of an Array?

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
jay mueller
Is it possible to add the values of an Array?
on Jul 13, 2020 at 11:29:45 pm

I'd like to have an expression to add the values of an array. I'm using sourceRectAtTime().width and xxxxx.name.match(keyword). If the amount of layers used would be constant, no problem. But they will change with each comp. (using characters in boxes to spell words). In my expression I only have the "x = Math.max(...widthlist); to see if the rest works. My goal is to keep the final word centered. Any help would be appreciated. Thanks.

keyword = "_Letter";
widthlist = [];

for ( i = 1; i &lt;= thisComp.numLayers; i++)
{
layerPath = thisComp.layer(i);

const layerPathWid = layerPath.sourceRectAtTime().width;
const layerPathSWid = layerPath.transform.scale[0];
const layerPathGetWid = ( layerPathSWid - 100)* .01;
const layerPathFinWid = layerPathWid + layerPathGetWid * layerPathWid;

if(layerPath.name.match(keyword)) {widthlist.push(layerPathFinWid)} else {};
};
x = Math.max(...widthlist);
[x,value[1]]


Return to posts index

Filip Vandueren
Re: Is it possible to add the values of an Array?
on Jul 14, 2020 at 10:28:34 pm

there is no sum() method,
but an array reducer function can do it.

something like this (using an arrow notation)


x = widthlist.reduce( (acc, curr) => acc + curr , 0 );




Return to posts index

jay mueller
Re: Is it possible to add the values of an Array?
on Jul 15, 2020 at 12:44:23 am

Thank you. Exactly what I needed.


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]