I would like to create a function that takes an object and returns true if the link id of the top level or any of the children matches a given ID. For example the link ID for Product paths is 51125095 so passing this ID into the function should result in true
Here is my sample object:
  const sampleObj = {
    id: '55259494',
    menuText: 'Top level link',
    link: {
      id: '55259472',
      slug: 'lop-level-link',
    },
    children: [
      {
        id: '53664310',
        menuText: 'Product paths',
        link: {
          id: '51125095',
          slug: 'product-paths',
        },
        children: [],
      },
      {
        id: '53664355',
        menuText: 'Testing',
        link: {
          id: '51272081',
          slug: 'testing',
        },
        children: [],
      },
      {
        id: '53664382',
        menuText: 'Relay',
        link: {
          id: '51489535',
          slug: 'relay',
        },
        children: [],
      },
      {
        id: '55259577',
        menuText: 'About us',
        link: {
          id: '55259487',
          slug: 'about-us',
        },
        children: [],
      },
    ],
  }
And here is the function I have started to build:
  const isObject = (value) => {
    return !!(value && typeof value === 'object' && !Array.isArray(value))
  }
  const containsActiveLink = (linkObject: any = {}, pageIDToMatch) => {
    if (isObject(linkObject)) {
      console.log('Run:' + linkObject.menuText)
      console.log(linkObject)
      if (linkObject.link.id === pageIDToMatch) {
        return true
      }
      if (linkObject.children.length > 0) {
        linkObject.children.map((child) => containsActiveLink(child, pageIDToMatch))
      }
    }
    return false
  }
  const isActiveLink = containsActiveLink(sampleObj, '51125095')
Any help will be greatly appreciated please