Function hasObj

  • Checks if a given object is within an array of objects. Checks for object equality using the compareObject function.

    Parameters

    • objArr: object[]

      The array of objects to check within.

    • data: object

      The object to find within the array.

    • Optional returnType: boolean = false

      If true, returns the found object; otherwise, returns a boolean indicating presence.

    Returns boolean | object

    Example

    const objArr = [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }];
    const data = { id: 1, name: 'John' };

    const result_1 = hasObj(objArr, data);
    console.log(result_1); // true

    const result_2 = hasObj(objArr, data, true);
    console.log(result_2); // { id: 1, name: 'John' }

Generated using TypeDoc