Shawn Shawn - 5 months ago 8
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

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.

Comments