constresult=(data)=>{let max =0;for(let i =0; i < data.length; i++){if(data[i]> max){
max = data[i];}}console.log("===> :: max", max);}const inputData =[2,3,5,4,54,69,4,44,3,6,45,6,4,6]result(inputData);
Find largest number from array by function in javascript
functionlargestElements(numbers){var largest =0;for(let i =0; i < numbers.length; i++){var elements = numbers[i];if(elements > largest){
largest = elements;}}return largest;}const numbers =[2,3,4,8,5,2,4];console.log(largestElements(numbers));//Output: 8
find the largest array from an array in javascript
const numbers =[[1,2,3],[4,5,6],[7,8,9,10,11],];let largestArray = numbers[0].length;for(let i =1; i < numbers.length; i++){if(numbers[i].length> largestArray){
largestArray = numbers[i];for(let j =0; j < largestArray.length; j++){console.log(numbers[i][j]);}}}//it will print 7, 8, 9, 10, 11 as these numbers are in largest array;
// first of all, i write a forEach loop function// raw fanctionfunctiongetArrayLargestElement(array){let largestElement ="";
array.forEach(largest);functionlargest(word){if(word.length> largestElement.length){
largestElement = word;}}return largestElement;}const banglaGit =["amader","sonar","bangladesh","ami tomay","onek ","valo basi",];console.log(getArrayLargestElement(banglaGit));// es6 arrow functionconstgetLargestArrowFunc=(array)=>{let largest ="";
array.forEach((word)=>{if(word.length> largest.length){
largest = word;}});return largest;};console.log(getLargestArrowFunc(["hello","world","md yeamin","i'm","here"]));