How do I find the greatest value in a list?

I have a list “heights” containing items as floats. I want to set a variable “highestValue” that updates every frame and returns the value of the greatest value in the list.

Floats are constantly being added and removed from the list, but I want to search through the list for the highest value every frame. Does anyone know the best way I could do that.

I’m using unity Javascript if it matters.

Since you have floats you can use Mathf.Max and pass the list converted to an array.

var myList : List.< float >;

// [...]

var maxValue = Mathf.Max(myList.ToArray());

Use Array.Sort() and arrayName[arrayName.length-1].