How to return values of other keys if user enters one other value in Javascript? [duplicate]

Issue

This Content is from Stack Overflow. Question asked by IDKcodinggod

const object = {
  array: [
    {
      key1: 'input1',
      key2: 'sampleValue1',
    },
    {
      key1: 'input2',
      key2: 'sampleValue2',
    },
  ],
};

How would I go about creating a function that check what key1 the user has inputed, and then return the value of key2? For example, if the user entered ‘input2’, then the function would return ‘sampleValue2’.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?