DEV Community

Andy Chen
Andy Chen

Posted on

useful array methods

Map

Contains

Reduce

Filter

forEach -

var test = [5, 6, 2]


var maxNumDeclarative = function(array) {
  // your code here
  var maxi = array[0]


  array.forEach((item) => { 
    if (item > maxi) 
    maxi = item;
   })


  // array.forEach(function (item) {
  //   if (item > maxi) {
  //     maxi = item;
  //   }
  // })


  return maxi;
};

maxNumDeclarative(test); ```



Enter fullscreen mode Exit fullscreen mode

Top comments (0)