Search code examples
javascriptregexparsingextendscriptafter-effects

Javascript parsing?


I'm coding something in extendscript for adobe after effects, which ends up being javascript.

I have an array and I would like to do a search for just the word "assemble" and return the whole jc3_RIG_008_masterLayer assemble string

var comps = ["_MAIN", "jc3_RIG_008_masterLayer assemble","jc3_RIG_008_masterLayer contact sheet", "[Z] source", "MM004 source"];

I'm not sure what the best/ most efficient way to achieve this is, but any thoughts would help.

Thanks.


Solution

  • @josegomezr has the right idea using a simple loop. I updated that idea to return the string that the poster is looking for.

    var comps = ["_MAIN", "jc3_RIG_008_masterLayer assemble","jc3_RIG_008_masterLayer contact sheet", "[Z] source", "MM004 source"];
    var compWithAssemble;
    for(var i in comps){
        if(comps[i].indexOf("assemble") > -1){
            compWithAssemble = comps[i];
            break;
        }
    }
    // compWithAssemble has the string you are looking for.
    console.log(compWithAssemble);