JavaScript find max value in an array | find max value in array object
Find the max or min value from an array or an object As JavaScript Developer we usually need to work on arrays & array objects and sometimes we need to do some operations on arrays like searching, sorting, find min/max etc. So today's post we will see how to find max or min value from an array. So let's take an example of the following array. let arr = [21,32,43,34,42,5,6,2,43,23]; If we want to find the maximum value from the array, so code will be as follows: Math.max(…arr); If we print it then the output will be as follows: So this will provide the maximum value from the array element. ProTip: If you are not aware of ... the operator then just inline explanation is that this is Destructuring mechanism for an array so it provides values in the destructed format. If we want to find the minimum value from the array, so code will be as follows: Math.min(…arr); So this will provide the minimum value from the array element. If we print it then the output will be as follows: ...