JavaScript tips — Find if an array contains a value using Array.includes

Pubblicato il: 23 ottobre 2022
sul canale di: Code 2020
1,014
5

The Array includes method is the safest way to find if an array contains a given value in #javascript. You call it on the array you want to search with the value you want to search for. Includes return true if the value exists in the array and false if it does not.

Includes can be used to check if strings, numbers, and objects exist in an array. It does a strict comparision when searching (equivlent to the `===` comparision operator)

Many online resources still recomend using indexOf for this. IndexOf is fine if you need to find the index of a value in an array but is easy to misuse if you are checking if a value exists in an array since it returns number values.

https://developer.mozilla.org/en-US/d...


In questa pagina del sito puoi guardare il video online JavaScript tips — Find if an array contains a value using Array.includes della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code 2020 23 ottobre 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,014 volte e gli è piaciuto 5 spettatori. Buona visione!