• Check if one object is a subset of the other object. "Subset" means that all properties of one object are present in the other object, and if they are present that all values of those properties are deeply equal. Sub-objects are also checked to be subsets of the corresponding sub-object in the other object.

    Parameters

    • objectWithAllProperties: unknown

      Object to be checked if it is a superset of objectWithPartialProperties

    • objectWithPartialProperties: unknown

      Object to be checked if it is a subset of objectWithAllProperties

    Returns boolean

    True if objectWithAllProperties contains all the properties of objectWithPartialProperties and all values of those properties are deeply equal

    objA = { name: 'Alice', age: 30, address: { city: 'Seattle', state: 'Washington' } };
    objB = { name: 'Alice', address: { city: 'Seattle' } };

    It is important to note that only arrays of primitives (i.e., booleans, numbers, strings) are supported. In particular, objects in arrays will not be checked for deep equality. Also, presence in an array is all this checks, not the number of times that an item appears in an array. [1, 1] is a subset of [1].