I am trying to get the top 2 highest values from an object:
emotions = {
joy: 52,
surprise: 22,
contempt: 0,
sadness: 98,
fear: 60,
disgust: 20,
anger: 1,
};
I understand I can do Math.max()
with all these values, but it will return just the value of sadness in this example. Can I somehow get top 2, with label (sadness) and value (98)?