I have a simple JavaScript Array object containing a few numbers.
[267, 306, 108]
Is there a function that would find the largest number in this array?
I have a simple JavaScript Array object containing a few numbers.
[267, 306, 108]
Is there a function that would find the largest number in this array?
Run this:
And now try
[3,10,2].max()
returns10
I just started with JS but I think this method would be good:
how about using Array.reduce ?
The easiest syntax, with the new spread operator:
Source : Mozilla MDN
You could sort the array in descending order and get the first item:
You can also use forEach: