Metoda includes
Metoda includes kontrollon nëse një element
ndodhet në një array. Si parametër pranon vlerën që
do të kërkohet. Nëse ky element gjendet në array,
metoda kthen true,
ndryshe kthen false.
Sintaksa
javascriptarray.includes(elementi);
Shembull
Le të kontrollojmë nëse një element ndodhet në array:
javascriptlet arr = [1, 2, 3, 4, 5];
let res = arr.includes(3);
console.log(res);
Rezultati i ekzekutimit të kodit:
javascripttrue
Shembull
Supozoni tani që elementi i kërkuar nuk gjendet në array:
javascriptlet arr = [1, 2, 3, 4, 5];
let res = arr.includes(6);
console.log(res);
Rezultati i ekzekutimit të kodit:
javascriptfalse