apply()
MethodYou can use the Math.max()
and Math.min()
methods in combination with the apply()
method to find the maximum or minimum values within an array or an array-like object, like this:
<script>
var numbers = [1, 5, 2, -7, 13, 4];
var maxValue = Math.max.apply(null, numbers);
console.log(maxValue); // Prints: 13
var minValue = Math.min.apply(null, numbers);
console.log(minValue); // Prints: -7
</script>
See the tutorial on JavaScript borrowing methods to know the reason for using the apply()
method here. Alternatively, you can use the ES6 spread operator to perform the same task.
<script>
var numbers = [1, 5, 2, -7, 13, 4];
var maxValue = Math.max(...numbers);
console.log(maxValue); // Prints: 13
var minValue = Math.min(...numbers);
console.log(minValue); // Prints: -7
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
What Is the Bashrc File Used For
If you are using Linux operating system...Laravel How to implement yajra datatable using yajra/laravel-datatables-oracle
In this article, we will share with you...How to get all the values from an associative array in PHP
Use the PHP array_values() fun...How to Get the Value of Selected Option in a Select Box Using jQuery
Use the jQuery :selected Selec...How to disabled Submit Button after Clicked using jQuery
Often times, users like to press a few t...