How to use the JavaScript Array includes method to determine whether or not an Array contains a specific item.
The method only returns a True or False answer.
Code Gist:
MDN site reference:
Nguồn:https://mcitmc.org/
Xem Thêm Bài Viết Khác:https://mcitmc.org/cong-nghe/
When you say in the first sentence "…the functionality available in the Array object…" would a more accurate description be "the Array prototype object"? I'm still trying to understand the concept of Prototypes in JavaScript that's why I'm asking.
Wonderful channel and very nice video, Steve! Clear and concise explanation of how the includes() array method determines whether or not an exact specified element exists within an array. I’d like to add that using the includes() string method in conjunction with certain array methods (the higher order functions) makes it easy to perform various operations on arrays. For example, you can use some() with includes() to determine whether or not a specified string exists within at least one element of an array:
const names = ['Mary', 'Jamie', 'Sarah'];
names.some ( e => e.includes("m") );
// true
Similarly, you can use filter() with includes() to return an array of elements which contain the specified string, and use toLowerCase() to ignore capitalization:
names.filter ( e => e.includes("m") );
// ["Jamie"]
names.filter(e=> e.toLowerCase().includes("m") );
// ["Mary", "Jamie"]
These and similar combinations make it easy to perform a wide array of operations. Happy New Year and Happy Coding to all! 🙂
The knowledge you have makes me wanna give up hahaha, you're a legend
Steve, you are the MDN of Youtube hahaha