The type of elements in the array.
The return type of the transformation function, if provided.
the target array to search and mutate.
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.
A new array with all matching elements, optionally transformed. If no match is found, an empty array is returned.
const pets = [
{ type: 'dog', name: 'Fido' },
{ type: 'dog', name: 'Chacalin' },
{ type: 'cat', name: 'Mr. Brown' },
{ type: 'cat', name: 'Night' },
]
console.log(PUtilsArray.extractOne(pets, pet => pet.type === 'dog'))
// => [
// { type: 'dog', name: 'Fido' },
// { type: 'dog', name: 'Chacalin' },
// ]
console.log(pets)
// => [
// { type: 'cat', name: 'Mr. Brown' },
// { type: 'cat', name: 'Night' },
// ]
Extracts (removes and returns) all elements in an array that match the given logical selector.