predictype / predicates/objects/objectKey / objectKey
objectKey(
source
,oper
,key
):boolean
Defined in: predicates/objects/objectKey.ts:28
Checks if an object has or lacks a specific key (string or symbol) using the specified operation.
object
The object to check.
The key operation to perform (e.g. ‘has_key’, ‘lacks_key’).
The key to check.
string |
symbol |
boolean
True if the key check is valid according to the operator, otherwise false.
If the operation is not recognized.
const obj = { foo: 1 };
const obj2 = {};
const sym = Symbol('baz');
Object.defineProperty(obj2, sym, { value: 2 });
objectKey(obj, 'has_key', 'foo'); // true
objectKey(obj, 'lacks_key', 'bar'); // true
objectKey(obj2, 'has_key', sym); // true
Supported Operators: