JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)

Corey Schafer · Beginner ·💻 AI-Assisted Coding ·11y ago

Key Takeaways

This video tutorial covers JavaScript Arrays, specifically the filter(), every(), and some() methods, and demonstrates their usage with examples using arrays of integers and objects.

Full Transcript

so what the filter method does is it runs every element in your array through a specified function and that function will look at every element and it will run it through a condition and if that condition returns true then that element gets added to a return array so filter returns an array of elements that met every condition in your function the best way to show you this is just to show you an example so for example here I have a an array with a bunch of random integers and then here I'm printing this array out to the screen so if we write a function called num over now this callback here is going to have access to the same parameters that we've seen before in the other callbacks it's going to have the element of the array the current index of the array and then it's going to have the original array that we're doing the operations on so for this example let's just return whether the element is greater than 20. and then down here where we have this VAR filtered array let's set this equal to the array dot filter and then let's pass in this num over function here and then let's print this filtered array out to the screen let me save that now you can see down here in this filter array every element is over 20. if I came up here to this num over function and said less than 20 and save that now if we come down here to the filtered array we can see it only pulled out the elements that were less than 20. so you can do any check within this function that you want and it will return a new array of all the elements that meet whatever condition it is that you specify so that is a simple example using some integers let's try an example using an object here and pretty much with the object you're just going to do the same thing that you did for the array of integers you see that our array here is an array of objects and each one of these objects has a name and an age so if we wanted to code if we wanted to filter out let's say ages over the age of 30 then I could say function filter age and like I said before you don't have to pass in all those parameters here I'm just going to pass in the element and then I'm going to return any element that is greater actually that's going to be element.age because this is now an object so we wanted to turn element.age over 30. and let's uncomment out this variable here and let's set this equal to array let's see this is array 14. 14 dot filter and pass in filter age and let's print this out to the screen save that and now we can see down in our filtered array we only have John and Steve because both of those are over the age of 30. so that is how the filter method works now let's go down here and take a look at the method every the every method is a little similar to the filter method but instead of it returning an array of all the element elements that meet the criteria it checks to see if every element meets the criteria and it returns a Boolean that is true or false saying whether all those elements met the criteria in the function so for example if I write a function is every and I'm just going to pass in the element here but it could also have access to the index and the original array and let's just return if every element is greater than 10. and then I will uncomment out this variable passed here and I'll set this equal to array 15 dot every and then I'm going to pass in this is every function and then I'm going to uncomment out this line here to print it out to the screen and you can see my every result is false because if we look at the array we have this value 4 here so every element in the array is not greater than 10 and as soon as it hits this 4 value it'll just return false immediately because it knows from that point on that not every value in the array is over 10. if I would change this 4 to a 14 and save that now you can see down here where I'm printing this out every result is equal to true because every value in this array is greater than 10. so that is a short example using an array of integers now let's take a look at an example that is using an array of objects and this is just the same array of objects I used last time with three elements here each having a name and an age so this time I'm going to write a function called all under and pass in the element and we will check if all of these elements are under the age of uh 50. so I will do element actually that'll be return element dot age is under 50. and let me uncomment out this variable here set array 15. every and we'll pass in this all under function and then let me output this to the screen I'll put that so we have the every result is false because every one of these elements does not have an age that is under the age of 50. if I would check if all of these ages are under the age of 60 and save that now you can see down here that my every result is true so that's a few examples of how the every method works let me comment that out and now let's take a look at the sum method now we'll just take a quick look at this one because it is so similar to the every method what sum does uh whenever we looked at every it would return false as soon as one of the elements didn't meet the criteria in the sum method it will return true as soon as one of the elements do meet the criteria so for example if I have a function here and I'm going to call this sum odd and I'm going to pass in the element now for some odd I'm just going to return whether the element mod 2 equals equals one and that will let us know whether this element is an odd number so then the uncomment out this variable here I'll set this equal to array 16. oh that sun and we will pass in the some odd function save that and let me output that to the screen and you can see that my sum result is false if we look at the array here every single one of these elements is even so it's saying that there are not there are not some of these some of these elements that are odd if I made one of these odd and I put this at 21 and save that now you can see that my sum result is true because it says are some of these odd looks at the array as soon as it hits this 21 it returns true because that's all it needs it just needs the one so that is our example with an array of integers really quick we will take a look at an array of objects it's the same array of objects that we've been using before with the name and the age and I'm just going to write a function here called sum age pass in the element and I will return whether the element dot age we will check if there are some people over 50. so let's do far past equals array 16 dot sum and then sum H save that let's output this to the screen save and you can see that our sum result is true because there is one person in here that has an age over 50 if I said are there some people in here that have an age over 60 and you can see down here that the sum result is now false so that is a quick look at the sum method now let's take a look at produce and reduce right

Original Description

JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7) In this series, we will take an in-depth look at JavaScript Arrays and everything we can do with them. In part 5, we will go over: filter(), every(), and some() Part 1: https://youtu.be/8JgU2WmrZXI Part 2: https://youtu.be/nAWVYFEzoY8 Part 3: https://youtu.be/cdPS-lmlwco Part 4: https://youtu.be/JskeRdu_X8Q ... Part 6: https://youtu.be/1gupsllu5wQ Part 7: https://youtu.be/qxzp4X6sfGo ✅ Support My Channel Through Patreon: https://www.patreon.com/coreyms ✅ Become a Channel Member: https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join ✅ One-Time Contribution Through PayPal: https://goo.gl/649HFY ✅ Cryptocurrency Donations: Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3 Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33 Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot ✅ Corey's Public Amazon Wishlist http://a.co/inIyro1 ✅ Equipment I Use and Books I Recommend: https://www.amazon.com/shop/coreyschafer ▶️ You Can Find Me On: My Website - http://coreyms.com/ My Second Channel - https://www.youtube.com/c/coreymschafer Facebook - https://www.facebook.com/CoreyMSchafer Twitter - https://twitter.com/CoreyMSchafer Instagram - https://www.instagram.com/coreymschafer/
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Corey Schafer · Corey Schafer · 18 of 60

1 Web fonts using CSS Font Face
Web fonts using CSS Font Face
Corey Schafer
2 Using Font Awesome in Desktop Applications (OS X)
Using Font Awesome in Desktop Applications (OS X)
Corey Schafer
3 Sublime Text 2: Setup, Package Control, and Settings
Sublime Text 2: Setup, Package Control, and Settings
Corey Schafer
4 ArcGIS API for JavaScript Part 1: Our First Web Map
ArcGIS API for JavaScript Part 1: Our First Web Map
Corey Schafer
5 Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Mac Tip: Windows' Snapping Feature on Mac with HyperDock
Corey Schafer
6 Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Linux/Mac Terminal Tutorial: Creating Aliases for Commands
Corey Schafer
7 ArcGIS API for JavaScript Part 2: Starting Templates
ArcGIS API for JavaScript Part 2: Starting Templates
Corey Schafer
8 Paver Patio Time Lapse
Paver Patio Time Lapse
Corey Schafer
9 Mac Tip: Ways to perform Screen Capturing and Screenshots
Mac Tip: Ways to perform Screen Capturing and Screenshots
Corey Schafer
10 WordPress Plugins: Imsanity
WordPress Plugins: Imsanity
Corey Schafer
11 WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
WordPress Tips: Test your theme with Theme Unit Test and Monster Widget
Corey Schafer
12 Sublime Text 3: Setup, Package Control, and Settings
Sublime Text 3: Setup, Package Control, and Settings
Corey Schafer
13 Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Understanding Binary, Hexadecimal, Decimal (Base-10), and more
Corey Schafer
14 Mac Tip: Adding Folder Stacks to the Dock
Mac Tip: Adding Folder Stacks to the Dock
Corey Schafer
15 CSS Tips and Tricks: Add External URLs to Print Stylesheets
CSS Tips and Tricks: Add External URLs to Print Stylesheets
Corey Schafer
16 JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 7 of 7)
Corey Schafer
17 JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 1 of 7)
Corey Schafer
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 5 of 7)
Corey Schafer
19 JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 4 of 7)
Corey Schafer
20 JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 3 of 7)
Corey Schafer
21 JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 2 of 7)
Corey Schafer
22 JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
JavaScript Arrays: Properties, Methods, and Manipulation (Part 6 of 7)
Corey Schafer
23 Python Tutorial: if __name__ == '__main__'
Python Tutorial: if __name__ == '__main__'
Corey Schafer
24 Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Sublime Text Quick Tip: "Go To Definition" Click Shortcut
Corey Schafer
25 How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
How to quickly create favicons for the desktop, Apple/Android devices, tablets, and more
Corey Schafer
26 Easily Resize Multiple Images Using Picasa
Easily Resize Multiple Images Using Picasa
Corey Schafer
27 Easily Resize Multiple Images Using the Mac Terminal
Easily Resize Multiple Images Using the Mac Terminal
Corey Schafer
28 Python Tutorial: virtualenv and why you should use virtual environments
Python Tutorial: virtualenv and why you should use virtual environments
Corey Schafer
29 Python Tutorial: pip - An in-depth look at the package management system
Python Tutorial: pip - An in-depth look at the package management system
Corey Schafer
30 Git Tutorial: Using the Stash Command
Git Tutorial: Using the Stash Command
Corey Schafer
31 How Software Engineers, Developers, and Designers can volunteer their skills
How Software Engineers, Developers, and Designers can volunteer their skills
Corey Schafer
32 Git Tutorial: Diff and Merge Tools
Git Tutorial: Diff and Merge Tools
Corey Schafer
33 Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Git Tutorial: Change DiffMerge Font-Size on Mac OSX
Corey Schafer
34 Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Sublime Text Quick Tip: Launch Sublime Text from the Terminal
Corey Schafer
35 Python Tutorial: str() vs repr()
Python Tutorial: str() vs repr()
Corey Schafer
36 Programming Terms: DRY (Don't Repeat Yourself)
Programming Terms: DRY (Don't Repeat Yourself)
Corey Schafer
37 Programming Terms: String Interpolation
Programming Terms: String Interpolation
Corey Schafer
38 Programming Terms: Idempotence
Programming Terms: Idempotence
Corey Schafer
39 Python Tutorial: Namedtuple - When and why should you use namedtuples?
Python Tutorial: Namedtuple - When and why should you use namedtuples?
Corey Schafer
40 Programming Terms: Mutable vs Immutable
Programming Terms: Mutable vs Immutable
Corey Schafer
41 Python Tutorial: Else Clauses on Loops
Python Tutorial: Else Clauses on Loops
Corey Schafer
42 Overview of Online Learning Resources
Overview of Online Learning Resources
Corey Schafer
43 Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Mac OS X Terminal Tutorial: Time-Saving Keyboard Shortcuts
Corey Schafer
44 Git Tutorial for Beginners: Command-Line Fundamentals
Git Tutorial for Beginners: Command-Line Fundamentals
Corey Schafer
45 Quickest and Easiest Way to Run a Local Web-Server
Quickest and Easiest Way to Run a Local Web-Server
Corey Schafer
46 Python Tutorial: Generators - How to use them and the benefits you receive
Python Tutorial: Generators - How to use them and the benefits you receive
Corey Schafer
47 Python Tutorial: Comprehensions - How they work and why you should be using them
Python Tutorial: Comprehensions - How they work and why you should be using them
Corey Schafer
48 Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Chrome Quick Tip: Quickly Bookmark Open Tabs for Later Viewing
Corey Schafer
49 Programming Terms: Combinations and Permutations
Programming Terms: Combinations and Permutations
Corey Schafer
50 Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Git Tutorial: Difference between "add -A", "add -u", "add .", and "add *"
Corey Schafer
51 Preparing for a Python Interview: 10 Things You Should Know
Preparing for a Python Interview: 10 Things You Should Know
Corey Schafer
52 SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
SQL Tutorial for Beginners 1: Installing PostgreSQL and Creating Your First Database
Corey Schafer
53 SQL Tutorial for Beginners 2: Creating Your First Table
SQL Tutorial for Beginners 2: Creating Your First Table
Corey Schafer
54 SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
SQL Tutorial for Beginners 3: INSERT - Adding Records to Your Database
Corey Schafer
55 Linux/Mac Terminal Tutorial: Navigating your Filesystem
Linux/Mac Terminal Tutorial: Navigating your Filesystem
Corey Schafer
56 Python: Ex Machina Easter Egg - Hidden Message within the Code
Python: Ex Machina Easter Egg - Hidden Message within the Code
Corey Schafer
57 Mac Tip: New Split Screen Feature in El Capitan
Mac Tip: New Split Screen Feature in El Capitan
Corey Schafer
58 Setting up a Python Development Environment in Eclipse
Setting up a Python Development Environment in Eclipse
Corey Schafer
59 Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
Corey Schafer
60 SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
SQL Tutorial for Beginners 4: SELECT - Retrieving Records from Your Database
Corey Schafer

This video tutorial teaches how to use filter(), every(), and some() methods in JavaScript Arrays to manipulate and check array elements. It provides examples using arrays of integers and objects.

Key Takeaways
  1. Create a callback function to use with filter()
  2. Apply filter() to an array to create a new array with elements that meet a condition
  3. Use every() to check if all elements in an array meet a condition
  4. Utilize some() to determine if at least one element in an array meets a condition
  5. Apply these methods to arrays of objects
💡 The filter(), every(), and some() methods can be used to manipulate and check array elements in JavaScript, making it easier to work with arrays and perform common operations.

Related AI Lessons

Up next
Azure Security Priorities for 2026: Identity, Governance, AI Security & Zero Trust
Valto Microsoft Specialists
Watch →