The type of elements in the array.
The return type of the transformation function, if provided.
The target array to search in.
The selector used to identify the matching element. This can be either a predicate function or an object for property-based matching.
Optional
transform: (element: T, i: number) => KA function to transform the selected element before returning it.
The first matching element, optionally transformed.
const pets = [
{ type: 'dog', name: 'Fido' },
{ type: 'dog', name: 'Chacalin' },
{ type: 'cat', name: 'Mr. Brown' },
{ type: 'cat', name: 'Night' },
]
console.log(PUtilsArray.queryOne(pets, pet => pet.type === 'dog'))
// => { type: 'dog', name: 'Fido' }
console.log(PUtilsArray.queryOne(pets, { type: 'dog' }))
// => { type: 'dog', name: 'Fido' }
console.log(PUtilsArray.queryOne(pets, { type: 'cat' }, pet => pet.name))
// => 'Mr. Brown'
Gets the first element in the array that matches the given logical selector.