• JMap.Util.Array.findByProperty

    Search for first element in the given object array, for a given attribute name and value.

    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

    Returns T | undefined

    the found object, undefined if not found

    Example

    const myObjects = [{
    id: 1,
    name: "Green"
    }, {
    id: 2,
    name: "Red"
    }, {
    id: 3,
    name: "Blue"
    }]
    // search for an object in the given array, having attribute "name" equals to "red", and returns found object or undefined
    const foundObject = JMap.Util.Array.findByProperty(myObjects, "name", "Red")
    console.log(`Found object: "${JSON.parse(foundObject)}"`)
    // display message 'Found object: "{ \"id\": 2, \"name\": \"Red\" }"'