How to get the min and max value of a property in an array of objects with JavaScript

1 Answer

0 votes
const objArr = [
  { id: 3, language: 'javascript' },
  { id: 2, language: 'node.js' },
  { id: 8, language: 'typescript' },
  { id: 7, language: 'php' },
  { id: 4, language: 'c++' }
];

const ids = objArr.map(object => {
  	return object.id;
});

const max_id_value = Math.max(...ids);
console.log(max_id_value); 

const min_id_value = Math.min(...ids);
console.log(min_id_value);

  
  
  
  
/*
run:
  
8
2
  
*/

 



answered Jul 9, 2022 by avibootz
edited Jul 9, 2022 by avibootz
...