0
Object { "07.03.2022": "106", "08.03.2022": "114" }

i want to get the value (e.g. 114) from the known date 08.03.2022

I've already managed to do it the other way around:

const keyx = Object.keys(response.activeDates)[Object.values(response.activeDates).indexOf('114')];

but how can i get the 114 as result from the known 08.03.2022 ?

this don´t work:

var xto = "08.03.2022";
console.log(response.activeDates.xto);

Thanks!

  • 1
    if the object in the question can be called as `data` then `data["08.03.2022"]` will give you `"114"` – Nitheesh Feb 21 '22 at 14:11
  • I'm a little surprised you used `.keys(d)[.values(d)..]` but didn't try the reciprocal `.values(d)[.keys(d)...]` : `Object.values(response.activeDates)[Object.keys(response.activeDates).indexOf("08.03.2022")]` - while this does work, it's not ideal and not needed, but seems the obvious step from what you have that's working. – freedomn-m Feb 21 '22 at 14:41

1 Answers1

1

Did you try like this:

console.log(response.activeDates[xto])

When you are using xto it will look for the key named xto and not the value of that variable.

Radu Diță
  • 13,476
  • 2
  • 30
  • 34
  • 1
    To add: the attempted `response.activeDates.xto` is the equivalent of `response.activeDates["xto"]` (extra quotes) – freedomn-m Feb 21 '22 at 14:35