I have a simple code which returns the highest number value from an array.
const getMax = (data) => Object.entries(data).reduce((max, item) => max[1] > item[1] ? max : item);
var myData1 = { a: 1, b:2, c: 3};
var myData2 = { a: 4, b:2, c: 3};
console.log(getMax(myData1));
console.log(getMax(myData2));
Return result:
[ 'c', 3 ]
[ 'a', 4 ]
This whole function is important to run for other purposes, but please how would I specifically print the output of only first calculated value (so 'c' or 'a') and then print specifically output of the second value (so 3 or 4)?
Thank you.
getMax(myData1)[0]