June 5, 2023
Program to use JavaScript Array includes() method
let a = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let b = a.includes('Lion');
console.log(b);
Output
true
Steps Description
- Declare two variable
a
andb
- Initialize two variable
a
andb
with value of arraya = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
andb = a.includes('Lion')
Array includes()
method checks the statement in all elements of the given array, returns true if found, false if not found- The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array includes() method
let c = [1,2,3,4,5];
let d = c.includes(8);
console.log(d);
Output
false
Steps Description
- Declare two variable
c
andd
- Initialize two variable
c
andd
with value of arrayc = [1,2,3,4,5]
andd = c.includes(8)
Array includes()
method checks the statement in all elements of the given array, returns true if found, false if not found- The value of
d
variable is displayed with the help of console.log inbuilt function
by : Suhel Akhtar
Quick Summary:
JavaScript Array includes() method 2 example