0

I have a Javascript object like this :

Const dataStructure = {
1 : 2000, 
2 : 1950,
// and so on

On the other side I have a userInput, I want to find the matched key for it and get the value of that key to send it as a response ti user.

So I go through different solutions(for, forIn and...), but I couldn't retrieve the value

I appreciat your answers

  • I'm not sure I understand. It's just a bunch of numeric keys; get a number and return the value at that key. – Dave Newton Feb 06 '20 at 21:20
  • And we appreciate if you share with us what you've tried, since we avoid to just write full code, we prefer to guide and help to fix issues – Calvin Nunes Feb 06 '20 at 21:20

1 Answers1

0

If your user input is saved to var USER_INPUT, you could do something like the following:

console.log(dataStructure[USER_INPUT])
Greg
  • 1,845
  • 2
  • 16
  • 26