BUPKIS
    Preparing search index...

    Function has

    • Returns whether a value exists at a given keypath within an object using dot or bracket notation.

      Supports keypaths like:

      • 'foo.bar' - dot notation
      • 'foo[1].spam' - bracket notation with array indices
      • 'foo["bar-baz"].quux' - bracket notation with quoted strings
      • "foo['bar-baz'].quux" - bracket notation with single quotes

      This function cannot consider values associated with symbol keys.

      Parameters

      • obj: unknown

        The object to examine the value from

      • keypath: string

        The keypath using dot or bracket notation

      Returns boolean

      true if the keypath exists, false otherwise

      const obj = {
      foo: {
      bar: 'hello',
      'bar-baz': { quux: 'world' },
      },
      arr: [{ spam: 'eggs' }],
      };

      has(obj, 'foo.bar');
      has(obj, 'arr[0].spam');
      has(obj, 'foo["bar-baz"].quux');
      has(obj, 'foo.nonexistent');