To check if a specified element is present in an array in JavaScript, you can use methods like includes
.
In this example,
numbers
with values 10, 20, 30, 40, 50.includes
method to check if element 30 is present in the array.includes
method returns true if the element is found, otherwise false.const numbers = [10, 20, 30, 40, 50];
const isPresent = numbers.includes(30);
console.log(`Element 30 is present: ${isPresent}`);
Element 30 is present: true
In this example,
numbers
with values 10, 20, 30, 40, 50.includes
method to check if element 60 is present in the array.includes
method returns true if the element is found, otherwise false.const numbers = [10, 20, 30, 40, 50];
const isPresent = numbers.includes(60);
console.log(`Element 60 is present: ${isPresent}`);
Element 60 is present: false
In this tutorial, we learned How to check if Specified Element is present in the Array in JavaScript language with well detailed examples.