I\'m trying to create a JavaScript function which takes information from an array in an external JSON and then takes the max value (or the top 5 values) for one of the JSON
My solution here. Remember to use == instead of === to compare a number with a string.
const getMax = (arr, prop) => {
const tmp = arr.map(x => x[prop]);
const max = Math.max(...tmp);
return arr.filter(x => x[prop] == max);
}
getMax(myArr,"bpg")
One line version:
myArr.filter( x => x["bpg"] == Math.max(...myArr.map(x => x["bpg"])) )