• JMap.Util.Array.removeByProperty

    Remove the first occurence.

    Type Parameters

    • T extends object

    Parameters

    • array: T[]

      the array

    • propertyName: string

      the object property name

    • value: any

      object's value for the given property name

    • Optional nonStrict: boolean

      by default test the value like "===", if nonStrict is true, will test like "=="

    Returns T[]

    the given array (and not a copy)

    Example

    const myObjects = [{
    id: 1,
    name: "Green"
    }, {
    id: 2,
    name: "Red"
    }, {
    id: 3,
    name: "Blue"
    }]
    // remove in the array the object that have a property "name" equals to "Red"
    JMap.Util.Array.removeByProperty(myObjects, "name", "Red")
    console.log(`myObjects: [${myObjects.join(", "")}]`)
    // display message 'myObjects: [{ \"id\": 1, \"name\": \"Green\" }, { \"id\": 3, \"name\": \"Blue\" }]'