Skip to content
Advertisement

How to get max and min value from Array in Javascript?

i had seen lots of another examples like

Math.max(...Array1) or Math.max(null,num) or Math.max.apply(null,num)
but it’s not working by my code
my data size is 255 and This is what the data looks like when i print it by console.log

JavaScript

Data was extracted from the json file and then put into the array through push.
code is look like this

JavaScript

Thank you for reading this.

Advertisement

Answer

Math.max(...[]) is ES6 syntax. Maybe you are using an older JavaScript engine? Here are two versions using your data as input, one for newer ES6, one for older ES5:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement