-2

I am looking for the most efficient way to retrieve the max value from the following object (outputted by dev console on Google) - knowing that the maximum value is 1002 but knowing it can dynamically change:

[Red: 1002, Orange: 24, Blue: 301, Pink: 106]

Any suggestions?

DreadedSlug
  • 497
  • 1
  • 7
  • 21
  • 1
    https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Math/max – Aalexander Jan 08 '21 at 19:25
  • 4
    i see no array ... – Nina Scholz Jan 08 '21 at 19:25
  • Does this answer your question? [Find the min/max element of an Array in JavaScript](https://stackoverflow.com/questions/1669190/find-the-min-max-element-of-an-array-in-javascript) – Naren Jan 08 '21 at 19:25
  • That isn't a valid array in your question. Is it supposed to be an object? Do you need the name of the color or just the number? – John Montgomery Jan 08 '21 at 19:27
  • best would be do an array of objects – Aalexander Jan 08 '21 at 19:28
  • 1
    although that's no array, this should answer your question [Fast way to get the min/max values among properties of object](https://stackoverflow.com/questions/11142884/fast-way-to-get-the-min-max-values-among-properties-of-object) – Gabriel Cabrera Jan 08 '21 at 19:34

1 Answers1

0

That seems to be an Object, not an Array. const max = Math.max(...Object.values(yourObject)) will do it.

Zac Anger
  • 6,983
  • 2
  • 15
  • 42