
Join the Conversation!
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.
In this lesson, you'll learn about the method in JavaScript, which is used to determine whether an array contains a specific value.
The method checks if an array contains a certain value and returns or based on the result. This method is case-sensitive, meaning it distinguishes between uppercase and lowercase letters.
Let's say we're a librarian looking for a particular book inside a "bookshelf" array:
var bookshelf = ["Moby Dick", "Little Women", "The Great Gatsby", "Pride And Prejudice"];
Here's how you can use the method to check for a specific book:
if (bookshelf.includes("Moby Dick")) {
console.log("The book you were looking for was found.");
} else {
console.log("Couldn't find the book, sorry. :c");
}
The method is a straightforward and efficient way to check for the presence of a value in an array , making it a useful tool for data validation and search operations in JavaScript.
"Please login to view comments"
Subscribing gives you access to the comments so you can share your ideas, ask questions, and connect with others.