how to get maximum of value between multiple keys from array?
I have tried this below method for only three(not multiple) keys.
getMaxValuefromkeys(values: any[], key1: string, key2: string, key3: string) {
var val1 = Math.max.apply(Math, values.map(function (a) { return a[key1] }));
var val2 = Math.max.apply(Math, values.map(function (a) { return a[key2]; }));
var val3 = Math.max.apply(Math, values.map(function (a) { return a[key2]; }));
if (val1 >= val2 || val1 >= val3) {
return val1;
} else if (val2 >= val3 || val2 >= val1) {
return val2;
}
return val3;
}
But we need to check more condition and write more codes if we use multiple keys. So I have tried these below codes
Math.max.apply(Math, values.map(function (a) { return a[key1], a[key2], a[key3]; }));
// where I want to return multiple keys
But it's not working. Is any single line of code available for getting max value in between multiple keys from array?