JavaScript Array includes method

preview_player
Показать описание
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.

Рекомендации по теме
Комментарии
Автор

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! :)

marcoanello
Автор

Steve, you are the MDN of Youtube hahaha

CameronChardukian
Автор

Thank you very much, with no exaggeration YOU are the best.

rotrose
Автор

wow! you are a hero there. Thanks for explaining properly and more understandable. Gonna watch again if I forgot how things done..

iamaprilabatas
Автор

I could understand that it is very similar to "some". In fact I fail to understand how are they different ??

Mentioning MDN, I was very disappointed to see that they do not support flex's space-evenly. I find it most valuable. Anyway that was aside of the topic.

Thank you.

mocococo
Автор

The knowledge you have makes me wanna give up hahaha, you're a legend

eh-lodo
Автор

Very well explained. 1qq...if we want to find the position of particular element as you mentioned in the video, what can we do? And if we need to find the closest position of 1 element from position of 2nd element, what can we do here? TIA

kalpanachaudhari
Автор

Is it possible to do the same with a one-dimensional array of objects? I have an array with people's names/ages/locations etc and I'm trying to check whether every continent is represented with my array of objects.

dfgndfghdfghdfgh
Автор

i believe line 20 should still say "after index 2". Or, "after and including index 3"

johnywhy
Автор

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.

creativestarfox
Автор

Hello sir, nice video.👍
Please can you tell me how to show that particular element of the targetted array on our search into the console, i.e if we search and if it is included then it should show on the screen🙏🙏

abhay
Автор

this is doing a linear search internally?

jasbindarsingh
Автор

nice - how do i do the same thing with an array of unique numbers?

christinakarlhoff