DEV Community

Discussion on: 🔥 Getting the largest number from an array

Collapse
 
dtinth profile image
Thai Pangsakulyanont • Edited

If you don't have to deal with large arrays (more than 100000 elements), then this approach works fine.

However if the array is large, please bear in mind that JavaScript runtimes have a limitation on the number of arguments that you can pass to a function. Yes, this include spread parameters.

If you pass more arguments than the limit, “Maximum call stack size exceeded” errors happen.

I have to find the maximum and minimum value of very huge arrays. For this I'm using

Math.max.apply(Math, my_array);
Math.min.apply(Math, my_array);

It works good on Firefox and IE, but on Chrome I always get Maximum call stack size exceeded errors... my current array has 221954 elements, and that's not my…