课程: JavaScript: Arrays

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Advanced methods 1

Solution: Advanced methods 1

(upbeat music) - [Narrator] In this challenge, we've been given an array of applicants. Each item in this array is an object with a name and an age. And in order to find our solution, we're looking to return an array that has filtered only those applicants who are 18 years or older. So for this particular challenge, we're going to use the array method filter, and filter is actually one of my favorite array methods, as strange as it may sound, but I think it's really powerful and it's really been helpful for me. So the first thing I'm going to do is just write my return statement. We don't need to, you could set a new variable and create your new array that way. I just prefer for simplicity sake to just go ahead and return what we will transform here. So we'll start with our applicants, our existing array. And remember, when we apply filter, it's going to return a new array that fits the criteria that we provide. So we'll say applicants filter, and then I'm just going to call this app…

内容