Checking an object that contains arrays of objects for a value

I see this question has been touched on a lot on stack overflow but I can’t seem to find one that helps my issue. I have an object that contains many arrays with objects nested inside. I need to find the key of the array that contains the object that a usersID. Ive tried .filter and for in loops but I keep getting errors.

My data looks like this :

  FL: [{id: "mp-2d24973e-c610-4b1c-9152...}{id...}],
  TX: [{id: "mp-2d24973e-c610-4b1c-9152...}{id...}],
  LA: [{id: "mp-2d24973e-c610-4b1c-9152...}{id...}],

Is there a method that allows me to check for a value inside the arrays and if it is found returns the key to that array ie. FL or TX?

const practices = data.items
for (const [key, value] of Object.entries(practices)){
          console.log(key, value, "KEYVALUE")
          if( === currentUser.currentPracticeID){

Of course this code doesnt work but this what Ive tried so far. Im still new to dev so any point in the right direction would be great.


A simple filter() inside of a loop would do it. After looking at the other answers, I should say this will return the first matching ID, rather than an array of all matching ID’s like @Barmars answer

const practices = {
  FL: [{id: "mp-2d24973e-c610-4b1c-9152"},{id:"3"}],
  TX: [{id: "mp-2d24973e-c610-4b1c-9153"},{id:"4"}],
  LA: [{id: "mp-2d24973e-c610-4b1c-9154"},{id:"5"}],

const findUserKey = (u) => {
  for (const key in practices) {
    if (practices[key].filter(mp => === u.currentPracticeID).length>0) return key
  return false;

let currentUser = {currentPracticeID: "mp-2d24973e-c610-4b1c-9154"}
let check_mp = findUserKey(currentUser)