Тёмный

JavaScript Array filter method 

Steve Griffith - Prof3ssorSt3v3
Подписаться 101 тыс.
Просмотров 18 тыс.
50% 1

How to use the JavaScript Array filter method to create a new array by extracting the desired elements from an existing Array.
Also includes a short example of using the Bitwise AND operator.
Code GIST can be found here: gist.github.com/prof3ssorSt3v...
Also see the Array map method for similar examples and more details on this functional programming method: • JavaScript Array map m...

Опубликовано:

 

5 июл 2017

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 56   
@noobyxd
@noobyxd 3 года назад
Your tutorials needs to be on top of every search list.
@charujain4308
@charujain4308 2 года назад
Best Instructor ever !!!! I know Javascript just because of you . I'm so glad I came across ur channel.
@TiffanyNg100
@TiffanyNg100 2 года назад
I always click on Steve Griffith's youtube green thumbnail whenever I search for any new javascript method! because I know I will get a good real life example and clear understand of the concept
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 года назад
The thumbnails became blue last year. 😀
@TiffanyNg100
@TiffanyNg100 2 года назад
@@SteveGriffith-Prof3ssorSt3v3 yeah i just realize, but because i currently just start leanring jaavscriot so most of the method i search seem like fit the old video year ago. thanks for shairng your video, your video is really short and consise . it really help me at a self-taught learner. im currently doing freecodecamp javascript algorithm and despite learning all the functions , i still cant wrap my head around how each and every method apply in real life. so i really struggle with algorithm and solving real problem. thats why i alwasy search for your video for quick reference
@samadivine
@samadivine 3 года назад
your voice make it easy for me to understand, very calm and pleasing to my ears
@brucewayne252
@brucewayne252 Год назад
Helpful and quite elaborately explained. Thank you Steve!
@rotrose7531
@rotrose7531 4 года назад
Thank you for introducing the bitwise filter concept, love it.
@haj5776
@haj5776 2 года назад
Awesome content and great voice, thank you professor Griffith
@danbonney9121
@danbonney9121 2 года назад
This is great! Exactly what I've been looking for. Thank you!
@johnywhy4679
@johnywhy4679 4 года назад
Thank you for the great wealth of tips you provide! Awesome vids.
@imanwilliams2910
@imanwilliams2910 4 года назад
I'm so grateful for this. You have no idea.
@rotrose7531
@rotrose7531 4 года назад
Second round, unfailingly amazing.
@iuliiasiriakivska2209
@iuliiasiriakivska2209 4 года назад
Thank you! Your explanations are top!!
@gary909
@gary909 5 лет назад
Really helpful, thanks very much!
@pavlobelenko2490
@pavlobelenko2490 6 лет назад
Great explanation!!! Thank you
@myindia5604
@myindia5604 3 года назад
very supersonic and attractive voice and a great explanation for each. thanks for such a great content.
@TSpartanDR
@TSpartanDR 7 лет назад
Very clear explanation! Thanks
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 7 лет назад
Thanks Spartan
@chesterxp508
@chesterxp508 2 года назад
Brilliant tutorials !!!
@thomascarlton82
@thomascarlton82 2 года назад
As usual, on point
@fahimal-huq6867
@fahimal-huq6867 3 года назад
Thanks a lot Sir.
@thickerthoughts9107
@thickerthoughts9107 4 года назад
Amazing stuff.
@mallimuondu6779
@mallimuondu6779 4 года назад
so useful thanks
@sshvibha
@sshvibha 4 года назад
thank you sir
@AdaKHansson
@AdaKHansson 2 года назад
Hi Steve! i'm wondering if there's a reason you're using the traditional function as opposed to an arrow function? :)
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 2 года назад
Arrow functions were not widely used 4 years ago when I recorded this tutorial.
@AdaKHansson
@AdaKHansson 2 года назад
@@SteveGriffith-Prof3ssorSt3v3 Of course 😅 I didn't check the date, your vids are awesome 😎👍
@CesarJuarezVargas
@CesarJuarezVargas 6 лет назад
Will the binary method operate if we'd like to extract the prime numbers?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 лет назад
There's not really a connection between the bitwise AND operator and prime numbers. We are just checking to see if the last bit in any number is a zero or a one.
@mallimuondu6779
@mallimuondu6779 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 so mind blowing mine works
@johnaweiss
@johnaweiss 4 года назад
Can you use arrow syntax, like this? let smallnumbers = numbers.filter(item => num < breakpoint);
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
As long as num and breakpoint are defined somewhere.
@johnaweiss
@johnaweiss 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 Can we say this? let smallnumbers = numbers.filter(newitem => olditem < breakpoint);
@moderncloth682
@moderncloth682 3 года назад
Damn, bitwise operators... cool.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 года назад
Here are a couple videos I did on them - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-EVvZLfJtAK8.html and ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-RRyxCmLX_ag.html
@moderncloth682
@moderncloth682 3 года назад
@@SteveGriffith-Prof3ssorSt3v3 Cheers, sir!
@ConsulthinkProgrammer
@ConsulthinkProgrammer 3 года назад
Thanks Sir. Suppose I have script like this: var leaveFilter = data.filter(data => {return data[1 == "Annual Leave" || data[1] == "Vacation leave" || data[1] == "Sick" || data[1] == "Important leave"}); How if I want make some iteration, or loop perhaps, so I just have to make that filter in array like this: filters = [ "Annual Leave", "Vacation leave", "Sick", "Important leave"] Which later I want that I could use that filters variable to do some iteration/loop in filter method above. Could you help to break this problem?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 года назад
Inside your filter function, use the Array includes function - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-iOml7u_sAVk.html const filters = [ "Annual Leave", "Vacation leave", "Sick", "Important leave"]; let filteredArray = data.filter( item => { return filters.includes( data[1] ); });
@ConsulthinkProgrammer
@ConsulthinkProgrammer 3 года назад
@@SteveGriffith-Prof3ssorSt3v3 Sir.. Really thanks.. it perfectly works. subscribed and love (like) your channel. Again big thanks Sir :)
@RedEyedJedi
@RedEyedJedi 4 года назад
Hey Steve, I was wondering if you could answer a question I have. In array methods like filter, map etc, the third parameter to the callback function is the array itself but you already have access to the array as you are using the method with it. For example, let copiedArray = arr.filter((item, index, array) => arr[index] === item); copiedArray will now contain everything arr contained. My question is, when would we need to access the array using the third parameter?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
Honestly, I can't think of a time when I have. However, maybe you want to do a loop inside the function through the array and compare against values that may have been previously altered.
@RedEyedJedi
@RedEyedJedi 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 Thanks for answering Steve. I'm still a bit uncertain why it's there as they both seem to be the same array.
@johnaweiss
@johnaweiss 4 года назад
If you used the modula operator for odd, how would you write the return statement?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
You would use an if else statement and return either true or false based on the result of zero or one. OR you could just return the value as 1 will be treated as truthy and 0 is falsey.
@johnaweiss
@johnaweiss 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 "just return the value as 1 will be treated as truthy and 0 is falsey" That's my preferred answer. Which is, i think, what you're doing with the bitwise operator, right? Is this correct? return num % 2;
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
@@johnaweiss return num % 2 will give you a new array with the odd values yes.
@johnaweiss
@johnaweiss 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 It won't give a new array with TRUE for the odd elements?
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
@@johnaweiss no. filter's function uses the true or false value to decide which items from the original array get passed to the new array.
@johnywhy4679
@johnywhy4679 4 года назад
Why can't we leave out the curlies in this case? There's only 1 line of code in the filter function. oldAges = Ages.filter (function (a) { return true } ) // WORKS oldAges = Ages.filter (function (a) return true ) // FAILS
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 4 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-f0FQYfxRGF8.html
@johnywhy4679
@johnywhy4679 4 года назад
@@SteveGriffith-Prof3ssorSt3v3 Thx, i watched the other vid. But didn't see answer. That vid is about arrow fx. (i revised my question above, sorry, maybe you were replying to my old question?)
@lukaakhalbedashvili7167
@lukaakhalbedashvili7167 3 года назад
ASMR
@johnywhy4679
@johnywhy4679 4 года назад
Why does this require semi-colon? oldAges = Ages.filter ((age) => {return age > 50; }) // WORKS oldAges = Ages.filter ((age) => {return age > 50 }) // FAILS
@johnywhy4679
@johnywhy4679 4 года назад
Why do all of these give "checkOld is not defined"? const oldAges = Ages.filter (checkOld) checkOld = age => age > 50; // "checkOld is not defined" checkOld = age => ( age > 50 ) // "checkOld is not defined" checkOld = age => {return age > 50 } // "checkOld is not defined" It seems you gave an overloaded answer in the vid linked below, line 31. But you chained two arrow fx, so now i have to try and break it down to just one. Would be super-helpful if at some point before this you showed how to do array fx with just a single arrow fx. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-WnP_ssWDBWU.html thx!
Далее
JavaScript Array reduce method
7:49
Просмотров 16 тыс.
We will see who will do it better 😂
00:14
Просмотров 4 млн
У тебя проблемы?
00:20
Просмотров 781 тыс.
ES6 Iterator & Generator Fundamentals
18:18
Просмотров 31 тыс.
JavaScript Array every method
4:14
Просмотров 12 тыс.
Chrome Dev Tools Console Super Powers
16:44
Просмотров 5 тыс.
COBOL Tutorial : Learn COBOL in One Video
2:13:59
Просмотров 266 тыс.
Understanding the Keyword THIS in JavaScript
13:59
Просмотров 8 тыс.
Hash Tables and Hash Functions
13:56
Просмотров 1,5 млн
Dynamic and Static Arrays
11:52
Просмотров 80 тыс.
How to Use the New JS Object GroupBy Method
18:17
Просмотров 3,4 тыс.
The Java Memory Model - The Basics
23:41
Просмотров 122 тыс.
We will see who will do it better 😂
00:14
Просмотров 4 млн