Check if user inputted string is in the array in JavaScript

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

We are required to write a JavaScript program that provides the user an input to enter a string value.

The program should then check the input value against some hard-coded array values. Our program should print true to the screen if the input string value is included in the array, false otherwise.


The code for this will be −

<!DOCTYPE html>
   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width">
   <title>CHECK EXISTENCE</title>
      const arr = ['arsenal', 'chelsea', 'everton', 'fulham',
      const checkExistence = () => {
         const userInput = document.getElementById("input").value;
         const exists = arr.includes(userInput);
         document.getElementById('result').innerText = exists;
   <input type="text" id="input">
   <button onclick="checkExistence()">Check</button>
   <p id='result'></p>


And the output on the screen will be −

Updated on 20-Nov-2020 13:38:41