Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Is it possible to add the values of an Array?

  • Is it possible to add the values of an Array?

    Posted by Jay Mueller on July 13, 2020 at 11:29 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 <= 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]]

    Jay Mueller replied 5 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Filip Vandueren

    July 14, 2020 at 10:28 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 );

  • Jay Mueller

    July 15, 2020 at 12:44 am

    Thank you. Exactly what I needed.

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy