@technobuddha > library > Object > Comparison
Function: shallowEquals()
ts
function shallowEquals(
objA:
| undefined
| null
| Record<string, unknown>,
objB:
| undefined
| null
| Record<string, unknown>,
exclude: string[]): boolean;Defined in: shallow-equals.ts:21
Compare two object for equality. Testing goes one level deep.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
objA | | undefined | null | Record<string, unknown> | undefined | First object to compare |
objB | | undefined | null | Record<string, unknown> | undefined | Second object to compare |
exclude | string[] | [] | Array of key names to exclude from the comparison |
Returns
boolean
true if the two objects have the same members
Example
typescript
const a = \{ x: 1, y: 2 \};
const b = \{ x: 1, y: 2 \};
shallowEquals(a, b); // true
shallowEquals(a, \{ x: 1 \}); // false
shallowEquals(a, \{ x: 1, y: 3 \}); // false
shallowEquals(a, b, ['y']); // true