Skip to content
Advertisement

Tag: max

Javascript – find highest value in an object of arrays of objects

I have an object containing arrays of objects. I’m trying to find the highest value of an object property, ‘sortOrder’ without manually iterating through the arrays and objects. So my variable looks like this following: So I’d be trying to iterate through this to eventually find, in this case, the highest sortOrder of 33. Not necessarily the array index or

Return index of greatest value in an array

I have this: What’s the best way to return the index of the highest value into another variable? Answer This is probably the best way, since it’s reliable and works on old browsers: There’s also this one-liner: It performs twice as many comparisons as necessary and will throw a RangeError on large arrays, though. I’d stick to the function.

Advertisement