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?
Yes of course exist:
Math.max.apply(null,[23,45,67,-45])
and the result return67
;Try this
How about this:
Using -
Array.prototype.reduce()
is cool![267, 306, 108].reduce((acc,val)=> (acc>val)?acc:val)
where acc = accumulator and val = current value;