Javascript forEach code to find large and small number from Array. Here is the Javascript code which help you to find biggest and smallest number from a given Array. Here we used forEach method loop the number of given arrays and find smallest and largest number.
Java Script Code:
let large,small,i;
let arr = [5, 4, 10, 68, 55];
large=small=arr[0];
arr.forEach((val) =>
{
if(val>large)
large=val;
if(val<small)
small=val;
})
console.log(“The smallest element is ” + small );
console.log(“The largest element is ” + large );
Output: