some
La méthode some() vérifie si au moins un élément d'un tableau satisfait une condition donnée.
Exemple interactif
Syntaxe
Signature classique
typescript
function some<
GenericInput extends readonly unknown[]
>(
input: GenericInput,
predicate: (
element: GenericInput[number],
params: ArraySomeParams<GenericInput>
) => boolean
): booleanSignature currifiée
typescript
function some<
GenericInput extends readonly unknown[]
>(
predicate: (
element: GenericInput[number],
params: ArraySomeParams<GenericInput>
) => boolean
): (array: GenericInput) => booleanParamètres auxiliaires
typescript
interface ArraySomeParams<
GenericInputArray extends readonly unknown[]
> {
index: number;
self: GenericInputArray;
}Paramètres
input: Le tableau à tester.predicate: Fonction de prédicat qui teste chaque élément. Reçoit l'élément, son index et le tableau complet.params.index: Position de l'élément courant.params.self: Le tableau complet (utile pour comparer la position ou accéder à un voisin).
Valeur de retour
true si au moins un élément satisfait la condition, false sinon.
Voir aussi
every- Vérifie si tous les éléments satisfont une conditionfind- Trouve le premier élément qui satisfait une condition
