Within an array of objects how does one find an object by a certain key name?

I have an an array of Object instances where each object’s own enumerable keys are based on digits only.

[{
  '2': [1, 3],
}, {
  '3': [1, 4],
}, {
  '4': [2, 6],
}]

I need to find the first array item of the first object which owns the digit based key that is provided as the base of my search.

Expected results:

  • providing the key value of 4 the expected result equals the number value 2.
  • providing the key value of 3 the expected result equals the number value 1.

40 thoughts on “Within an array of objects how does one find an object by a certain key name?”

Leave a Comment