ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Array value rather than content

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Array value rather than content
on Feb 7, 2018 at 9:21:01 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.


Return to posts index

Dan Ebberts
Re: Array value rather than content
on Feb 7, 2018 at 2:23:53 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



Return to posts index

Scott McGee
Re: Array value rather than content
on Feb 7, 2018 at 2:30:28 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
}
}


Return to posts index

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