I have an array in Javascript. I am also using jQuery - Had a question of to find the minimum value and maximum value inside the array.
Example:
var x = [23,42,44,1,45,29,99,99,102];
I have an array in Javascript. I am also using jQuery - Had a question of to find the minimum value and maximum value inside the array.
Example:
var x = [23,42,44,1,45,29,99,99,102];
Use Math.max
& Math.min
& apply
to get the value. The second paramater of apply
function accepts an array
var x = [23,42,44,1,45,29,99,99,102];
console.log(Math. max. apply(null, x)) // 102
console.log(Math. min. apply(null, x)) //1
var max = Math.max.apply(Math, array); // max value
var max = Math.max.apply(Math, array); // max value
var max_of_array = Math.max.apply(Math, array);