• Checks if a plain JavaScript object has a specified property.

    Example

    const myObject = { foo: 'bar', baz: 42 };
    hasProperty(myObject, 'foo');
    // => { ok: true, value: 'true' }

    hasProperty(myObject, 'qux')
    // => { ok: true, value: 'false' }

    Example

    Handle invalid input parameters:

    const user = { name: "John", age: 25 };
    hasProperty(null, "name");
    // => { ok: false, error: Error('[objects.hasProperty] Expected a plain javascript object') }

    hasProperty(user, null);
    // => { ok: false, error: Error('[objects.hasProperty] Expected an array of property keys') }

    Type Parameters

    • T extends Record<string, any>

    • K extends PropertyKey

    Parameters

    • obj: T

      The object to check for the specified property.

    • key: K

    Returns Result<boolean, Error>

    A Result object with either a boolean indicating whether the object has the specified property, or an Error object if the input parameters are invalid.

Generated using TypeDoc v0.24.7