The d3.max() function in D3.js is used to return the maximum value in the given array using natural order. If an array is empty then it returns undefined as output.
Syntax:
d3.max(Array)Parameters:
This function accepts parameters Array which is an array of elements whose maximum value is to be calculated. Here elements might be integers or any strings.
Return Value:
It returns the maximum value.
Example 1: This example shows the use of max() function.
<html>
<head>
<title>Getting maximum value</title>
</head>
<body>
<script src='https://d3js.org/d3.v4.min.js'>
</script>
<script>
// initialising the array of elements
let Array1 = [10, 20, 30, 40, 50, 60];
let Array2 = [1, 2];
let Array3 = [0, 1.5, 6.8];
let Array4 = [.8, .08, .008];
// Calling to d3.max() function
A = d3.max(Array1);
B = d3.max(Array2);
C = d3.max(Array3);
D = d3.max(Array4);
// Getting maximum value
document.write(A + "<br>");
document.write(B + "<br>");
document.write(C + "<br>");
document.write(D + "<br>");
</script>
</body>
</html>
Output:
60
2
6.8
0.8Example 2: This example shows the use of max() function.
<html>
<head>
<title>Getting maximum value</title>
</head>
<body>
<script src='https://d3js.org/d3.v4.min.js'>
</script>
<script>
// initialising the array of elements
let Array1 = [];
let Array2 = ["a", "b", "c"];
let Array3 = ["A", "B", "C"];
let Array4 = ["Geek", "Geeks", "GeeksforGeeks"];
// Calling to d3.max() function
A = d3.max(Array1);
B = d3.max(Array2);
C = d3.max(Array3);
D = d3.max(Array4);
// Getting maximum value
document.write(A + "<br>");
document.write(B + "<br>");
document.write(C + "<br>");
document.write(D + "<br>");
</script>
</body>
</html>
Output:
undefined
c
C
GeeksforGeeks