JavaScript Array filter method

  Рет қаралды 18,282

Steve Griffith - Prof3ssorSt3v3

Steve Griffith - Prof3ssorSt3v3

7 жыл бұрын

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...

Пікірлер: 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
@myindia5604
@myindia5604 3 жыл бұрын
very supersonic and attractive voice and a great explanation for each. thanks for such a great content.
@danbonney9121
@danbonney9121 2 жыл бұрын
This is great! Exactly what I've been looking for. Thank you!
@imanwilliams2910
@imanwilliams2910 4 жыл бұрын
I'm so grateful for this. You have no idea.
@johnywhy4679
@johnywhy4679 4 жыл бұрын
Thank you for the great wealth of tips you provide! Awesome vids.
@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
@TSpartanDR
@TSpartanDR 6 жыл бұрын
Very clear explanation! Thanks
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 6 жыл бұрын
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 😎👍
@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.
@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
@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 - kzbin.info/www/bejne/n4DQnWqrlNh0jM0 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 :)
@moderncloth682
@moderncloth682 3 жыл бұрын
Damn, bitwise operators... cool.
@SteveGriffith-Prof3ssorSt3v3
@SteveGriffith-Prof3ssorSt3v3 3 жыл бұрын
Here are a couple videos I did on them - kzbin.info/www/bejne/e4fZi3-cf9l0gZo and kzbin.info/www/bejne/iIPcqXajgb2Sl8k
@moderncloth682
@moderncloth682 3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Cheers, sir!
@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);
@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 жыл бұрын
kzbin.info/www/bejne/nGGpgoycrbd6fJo
@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. kzbin.info/www/bejne/jZ-zkKapjKl1jbc thx!
JavaScript Array reduce method
7:49
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 16 М.
Array Filter - Javascript In Depth
22:05
Tech with Nader
Рет қаралды 1,6 М.
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 45 МЛН
ROCK PAPER SCISSOR! (55 MLN SUBS!) feat @PANDAGIRLOFFICIAL #shorts
00:31
아이스크림으로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 4 МЛН
JavaScript filter Array Method in Depth
10:17
Zaiste Programming
Рет қаралды 7 М.
Real World Array Method Uses in JavaScript Web Development
24:18
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 12 М.
Custom Array Sorts in JavaScript
8:01
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 18 М.
Exercises: Array Filter - Javascript In Depth
31:46
Tech with Nader
Рет қаралды 1,5 М.
JavaScript filter() method in 6 minutes! 🚰
6:30
Bro Code
Рет қаралды 13 М.
A Simpler Way to See Results
19:17
Logan Smith
Рет қаралды 99 М.
Master JavaScript Array Reduce Method In 10 Minutes
10:51
Colt Steele
Рет қаралды 7 М.
Array Method filter map reduce
9:35
Telusko
Рет қаралды 63 М.
JavaScript Array Reduce
7:42
Programming with Mosh
Рет қаралды 333 М.
Became invisible for one day!  #funny #wednesday #memes
00:25
Watch Me
Рет қаралды 45 МЛН