Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Array value rather than content

  • Array value rather than content

    Posted by Scott Mcgee on February 7, 2018 at 9:21 am

    I have a conditional if/else expression

    if(thisLayer.name == “Word1”){
    loc = 0;
    } else if (thisLayer.name == “Word2”){
    loc = 1;
    } else loc = 2;

    As I have 8 of these, times by 8 I want to simplify it.

    varArray = [“Word1″,”Word2″,”Word3″,”Word4″,”Word5”];

    if I use the expression

    varArray[0] …. I get “Word1”

    How can I do it the other way, so if I tell it “Word1” it returns 0.

    Scott Mcgee replied 8 years, 6 months ago 2 Members · 2 Replies
  • 2 Replies
  • Dan Ebberts

    February 7, 2018 at 2:23 pm

    You could set it up as an associative array:

    var myArray = [];
    myArray[“Word1”] = 0;
    myArray[“Word2”] = 1;
    myArray[“Word3”] = 2;
    myArray[“Word4”] = 3;
    myArray[“Word5”] = 4;

    myArray[“Word3”] // should return 2

    Dan

  • Scott Mcgee

    February 7, 2018 at 2:30 pm

    Cheers Dan that works brilliantly.

    I was trying to use it in conjunction with referencing my Json file…Someone from IT had pointed out that you can title your keys. So they don’t have to be [0] or [1], you can give them values.

    So this works better than what I wanted to use it for. I’ve just posted it up as I could not find anything mentioning about labelling Json’s like this. So I think it’s worth sharing.

    {
    “bristol”:{
    “city”:”BRISTOL”,
    “condition1″:”Partly Cloudy”,
    “condition2″:”Partly Cloudy”,
    “condition3″:”Partly Cloudy”,
    “condition4″:”Partly Cloudy”,
    “condition5″:”Partly Cloudy”,
    “condition6″:”Partly Cloudy”,
    “maxtemp1”:6,
    “maxtemp2”:8,
    “maxtemp3”:8,
    “maxtemp4”:8,
    “maxtemp5”:8,
    “maxtemp6”:8,
    “windspeed1”:20,
    “windspeed2”:20,
    “direction1”:131,
    “direction2”:131
    },
    “bath”:{
    “city”:”BATH”,
    “condition1″:”Heavy Rain”,
    “maxtemp1”:4,
    “maxtemp2”:8,
    “windspeed1”:20,
    “windspeed2”:20,
    “direction1”:131,
    “direction2”:131
    }
    }

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