( obj: AnyObject, key: string )
| 1 | type AnyObject = { [key: string]: any }; |
| 2 | |
| 3 | export const findObjectWithKey = ( |
| 4 | obj: AnyObject, |
| 5 | key: string |
| 6 | ): AnyObject | null => { |
| 7 | if (obj.hasOwnProperty(key)) { |
| 8 | return obj[key]; |
| 9 | } |
| 10 | |
| 11 | for (const k in obj) { |
| 12 | if (typeof obj[k] === 'object' && obj[k] !== null) { |
| 13 | const result = findObjectWithKey(obj[k], key); |
| 14 | if (result !== null) { |
| 15 | return result; |
| 16 | } |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | return null; |
| 21 | }; |
no outgoing calls
no test coverage detected