How to Check if a JavaScript array contains a string
Learn how to use JavaScript array contains methods and techniques to check for different types of elements in arrays.
let colors = ["Red", "Green", "Blue"];
console.log(colors.indexOf("Green")); // Output: 1
console.log(colors.indexOf("White")); // Output: -1
How to Check if a JavaScript array contains a string
Feb 14, 2024, 6:48am UTC
Learn how to use JavaScript array contains methods and techniques to check for different types of elements in arrays.
let colors = ["Red", "Green", "Blue"];
console.log(colors.indexOf("Green")); // Output: 1
console.log(colors.indexOf("White")); // Output: -1
https://www.rajamsr.com/javascript-array-contains/