Activity › Forums › Adobe After Effects Expressions › expression to find highest number in array
-
expression to find highest number in array
Posted by Søren Kristensen on July 28, 2021 at 10:54 amI feel this should be very simple, but I can’t find the solution. I need an expression that determines which number in an array is the largest.
Raymundo Firmino De Oliveira Neto replied 3 years, 10 months ago 4 Members · 4 Replies -
4 Replies
-
Liran Tabib
July 28, 2021 at 11:32 amHi Soren
Let’s say tmpArr is your array, so you can loop through it and find the biggest one:
var biggestNum = tmpArr[0];
for(var i = 1;i < tmpArr.length;i++){
if(biggestNum < tmpArr[i]){biggestNum = tmpArr[i]}
}Cheers!
Liran Tabib
http://www.vdodna.com -
Tomas Bumbulevičius
August 4, 2021 at 7:57 amA bit simper one:
numArray = [1,10,5,3]
Math.max.apply(null, numArray)
-
Raymundo Firmino De Oliveira Neto
June 25, 2022 at 5:44 pmVery nice!! could you explain a little bit why it does work?
I was stuck trying to do it like that:
numArray = [1,10,5,3]
Math.max(numArray);
You saved me
Reply to this Discussion! Login or Sign Up