find highest value in array javascript
//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
max = Math.max.apply(null, arr);
//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)
var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
return Math.max(a, b);
});let numbers = [4, 13, 27, 0, -5]; // Get max value of an array in Javascript
Math.max.apply(null, numbers); // returns 27
//get min/max value of arrays
function getArrayMax(array){
return Math.max.apply(null, array);
}
function getArrayMin(array){
return Math.min.apply(null, array);
}
var ages=[11, 54, 32, 92];
var maxAge=getArrayMax(ages); //92
var minAge=getArrayMin(ages); //11const array1 = [1, 3, 2];
console.log(Math.max(...array1));const array = [10, 2, 33, 4, 5];
console.log(Math.max(...array)
)
Also in JavaScript:
- change style on click react
- transfer data from one component to another angular
- Enclose in Brackets
- javascript console error
- lexical scope javascript
- join two arrays javascript
- how to set html label value in jquery
- basic javascript
- javascript delete element
- jquery get second td of tr
- install node js in manjaro
- javascript split array into chunks
- event listener on parent not on childjavascript
- chartjs bar chart hover color
- JAVASCRIPT EVENT.TARGET
- drupal 8 get page node
- angular interview questions
- nodejs fs delete non empty directory
- replacing a value in string using aregular expression pyhton
- javascript create element in a new line
- angular on back skip routes
- creating a 2d array in js
- how to cast to javascript executor
- christmas