// Array to check
let array = [1, 2, 3, 4, 5];
// Element to check for in the array
let element = 3;
// Check if the array contains the specified element
let containsElement = array.includes(element);
// Display the result
console.log('Array Contains Element:', containsElement);
code
JavaScript Check if Array Contains Element
This JavaScript code uses the includes method to check whether the specified element (3 in this case) is present in the array. The result is then displayed in the console. The comments provide explanations for each part of the code.
Array
includes Method
Element Check