How JavaScript gets the maximum and minimum values from an array
Editor to share with you how JavaScript from the array to get the maximum and minimum values, I believe that most people do not understand, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
Get the maximum and minimum values from the array
You can use Math.max and Math.min to fetch the maximum and minimum values in an array:
Const numbers = [15, 80,-9, 90,-99] const maxInNumbers = Math.max.apply (Math, numbers) const minInNumbers = Math.min.apply (Math, numbers) console.log (maxInNumbers) > Result: 90console.log (minInNumbers) > Result:-99
You can also use ES6's. Operator to complete:
Const numbers = [1, 2, 3, 4]; Math.max (... numbers) > Result: 4Math.min (... numbers) > > Result: 1 is all the content of the article "how to get the maximum and minimum values from an array by JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!