• JMap.Util.Array.findIndexByProperty

    Search for first element index 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

    • Optional nonStrict: boolean

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

    Returns number

    the found index, -1 if not found

    Example

    const myObjects = [{
    id: 1,
    name: "Green"
    }, {
    id: 2,
    name: "Red"
    }, {
    id: 3,
    name: "Blue"
    }]
    // search for an object in the array that have attribute "name" equals to "red", and return its index position in the array
    const objectIndex = JMap.Util.Array.findIndexByProperty(myObjects, "name", "Red")
    console.log(`Object index: ${objectIndex}`)
    // display message 'Object index: 1'