How to find the object containing the highest value in an array

Baspa

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?

Nina Scholz

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.

edited at
0

Comments

0 comments
Login to comment

Related

array find the second highest value

How to iterate through array and find highest value: Java

C# find highest array value and index

Objective-C: How to find the highest value in an array without sorting?

Find the highest value in an array of hashes in Ruby

PHP find object has highest value in array

Get Highest value of Unique Values in Object Array

Return object with highest number from array containing multiple objects

Find highest value in multidimensional array and keep highest

C# How to find the other index if there exists duplicate value (find highest array value and index)?

How to display the highest value in an array

How do I find the highest value and swap it with the end value in an array?

How to find maximum value of a parameter in an object in an array?

How to I find lowest and highest value of this array (java)

Calculate object with highest value property in multidimensional array

How to get the index of highest value containing negative number from an array in javascript?

How to find a value in object of objects with an array of keys

How do I find the array index with its highest value with vhdl?

How to find the highest value of an array index of an HTML class using JQuery

How to take array object from the array object based on the highest value by a column in php

How to find the highest Value with Python

How to find the highest and smallest value

find highest key with value from Object

Javascript - find highest value in an object of arrays of objects

Find Object in an array that has the highest number of keys

Variation: Find the object with the highest value in Javascript

find highest value in Map <Object?, Object?>

How to find the array containing the smallest value?

How to find a value from array object in JavaScript?

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    pump.io port in URL

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  14. 14

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  15. 15

    How to use merge windows unallocated space into Ubuntu using GParted?

  16. 16

    flutter: dropdown item programmatically unselect problem

  17. 17

    Pandas - check if dataframe has negative value in any column

  18. 18

    Nuget add packages gives access denied errors

  19. 19

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  20. 20

    Generate random UUIDv4 with Elm

  21. 21

    Client secret not provided in request error with Keycloak

HotTag

Archive