Forums › Adobe After Effects Expressions › expression to find highest number in array
-
expression to find highest number in array
Raymundo Firmino De Oliveira Neto updated 1 month, 3 weeks ago 4 Members · 5 Posts
-
søren kristensen
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.
-
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 -
søren kristensen
July 28, 2021 at 12:14 pmthank you, works perfectly!
-
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
Viewing 1 - 5 of 5 posts
Log in to reply.