0

I apologize but I am very new to JavaScript. I have a toy object derived from two arrays. What I want to do is find the largest value of the make parameter (i.e., make = 3) and get an object that has all the parameters (i.e., make and model ) of make equal to 3

const arr1 = [1, 2, 3];
const arr2 = ['a', 'b', 'c'];
const myArr = [];

for(i = 0; i < arr1.length; i++){
    var myCar = new Object();
    myCar.make = arr1[i];
    myCar.model = arr2[i];
    myArr.push(myCar)
}
console.log(myArr);
>>> [ { make: 1, model: 'a' },
  { make: 2, model: 'b' },
  { make: 3, model: 'c' } ]
var mm = Math.max(...myArr.map(o => o.make))
console.log(mm)
>>> 3

I wish {make: 3, model: 'c'}

Gianni Spear
  • 7,033
  • 22
  • 82
  • 131

0 Answers0