I'm using a library that predicts the emotion of the user in front of the webcam. There are four emotions: angry, sad, surprised and happy. I want to check which emotion has the highest score. When i console.log predictedEmotions I see this:
(4) [{…}, {…}, {…}, {…}]
0: {emotion: "angry"value: 0.08495773461377512}
1: {emotion: "sad", value: 0.05993173506165729}
2: {emotion: "surprised", value: 0.054032595527500206}
3: {emotion: "happy", value: 0.18562819815754616}
Any ideas on how to get the emotion with the highest value?
You could reduce the array and take the object with the highest value. Then take take the emotion of the object.
var data = [{ emotion: "angry", value: 0.08495773461377512 }, { emotion: "sad", value: 0.05993173506165729 }, { emotion: "surprised", value: 0.054032595527500206 }, { emotion: "happy", value: 0.18562819815754616 }],
highest = data
.reduce((a, b) => a.value > b.value ? a : b)
.emotion;
console.log(highest);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments