find biggest number in javascript array code example

Example 1: find biggest number in javascript array

var peopleData = [ 
    { name: "Paul", height: 180, age: 21 },
    { name: "Johnny", height: 198, age: 43 },
    { name: "Brad", height: 172, age: 49 },
    { name: "Dwayne", height: 166, age: 15 }
];

//Find biggest height number
var maxHeight = 0;

for (var i = 0; i < heights.length; i++) {
    if (peopleData[i].height > maxHeight) {
        maxHeight = peopleData[i].height;
      //if you console.log(maxHeight); you should get 198
    }
}

Example 2: javascript largest number in array

const max = arr => Math.max(...arr);

Example 3: find highest value in array javascript

const array = [10, 2, 33, 4, 5];

console.log(Math.max(...array)
)

Example 4: function that search a biggest value in array javascript

function maisBaratosQue(valor, precos) {
   return precos.filter(p => p <= valor);
}

Tags:

Misc Example