Shawn Shawn -5 years ago 128
Javascript Question

Typescript find the the variable with the largest value

In TypeScripts/JavaScript,

How do I find the variable that contains the largest int value?

var id = 0; var ii = 1; var is = 2; var ic = 4;

Or how do I find the field that contains the largest int value?

{id : 0, ii : 1, is : 2, ic : 4}

Answer Source

Math.max will tell you the largest value of its arguments: Math.max(id, ii, is, ic). From there you can use the if statement.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download