• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

154
Vistas
Find max value in a Javascript Object and print all values

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'}

almost 3 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda