Recursively searches within an object, array, or any nested structure to find whether a specific key exists.
Handles circular references by tracking visited objects to prevent infinite recursion.
The object, array, or value to search within
The key to search for
Internal set for circular reference detection
True if the key is found anywhere in the structure, false otherwise
const obj = { a: 1, b: { c: 2, d: [{ e: 3 }] } };hasKeyDeep(obj, 'c');hasKeyDeep(obj, 'e');hasKeyDeep(obj, 'x'); Copy
const obj = { a: 1, b: { c: 2, d: [{ e: 3 }] } };hasKeyDeep(obj, 'c');hasKeyDeep(obj, 'e');hasKeyDeep(obj, 'x');
Recursively searches within an object, array, or any nested structure to find whether a specific key exists.
Handles circular references by tracking visited objects to prevent infinite recursion.