Search code examples
javascriptpolyfills

Polyfill for Math.max to make it useable for older browsers/systems


I am using the Math.max function but it is not available on all devices and browsers. Is there a Polyfill or an other easy and fast way to solve this?


Solution

  • The problem you have is not with Math.max as this has been supported since forever. It is with destructuring (... in Math.max(...array)). To get around that you can use older JavaScript which is quite likely supported. Try :

    Math.max.apply(null, array); (which does pretty much the same as Math.max(...array).