
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- How to find the largest number contained in a JavaScript array?
- Find the largest number in a Java array.
- Find the 3rd largest number in a Java array.
- Find the 2nd largest number in a Java array.
- How do I find the largest integer less than x in Python?
- How to find the second largest element in a user-input JavaScript array?
- Constructing largest number from an array in JavaScript
- How do I empty an array in JavaScript?
- How do I convert a float number to a whole number in JavaScript?
- Finding the largest non-repeating number in an array in JavaScript
- Java program to find the largest number in an array
- Find the difference of largest and the smallest number in an array without sorting it in JavaScript
- How to find the largest number?
- How do I remove a particular element from an array in JavaScript
- Java program to find the 3rd largest number in an array

Advertisements