-1

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];
vivianaranha
  • 2,781
  • 6
  • 33
  • 47

3 Answers3

1

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
brk
  • 48,835
  • 10
  • 56
  • 78
0

var max = Math.max.apply(Math, array); // max value
var max = Math.max.apply(Math, array); // max value

-1
var max_of_array = Math.max.apply(Math, array);
ntelio
  • 1
  • 1
  • Welcome to Stack Overflow! While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/q/114762/269535), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Suraj Rao Apr 30 '17 at 13:27