Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How Do I Find the Largest Number in a 3D JavaScript Array?
Let’s say the following is our array;
var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]];
Use the concept of flat() within the Math.max() to get the largest number.
Example
var theValuesIn3DArray = [75, [18, 89], [56, [97], [99]]];
Array.prototype.findTheLargestNumberIn3dArray = function (){
return Math.max(...this.flat(Infinity));
}
console.log("The largest number in 3D array is=");
console.log(theValuesIn3DArray.findTheLargestNumberIn3dArray());
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo202.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo202.js The largest number in 3D array is= 99
Advertisements
