find the largest number javascript code example
Example 1: javascript largest number in array
const max = arr => Math.max(...arr);
Example 2: get largest number in array javascript
const array1 = [1, 3, 2];
Math.max(...array1);
// expected output: 3
Example 3: find max value in javascript
x = findMax(1, 123, 500, 115, 44, 88);
function findMax() {
var i;
var max = -Infinity;
for (i = 0; i < arguments.length; i++) {
if (arguments[i] > max) {
max = arguments[i];
}
}
return max;
}