How to filter objects with keys in arrays in JavaScript

I am new to JavaScript and I cannot solve this problem:

Instructions
Use .filter() to return only the future students that are old enough to attend DevMountain (18+ only, please).
Assign the result of filtering futureStudents to a variable called oldEnough

var futureStudents = [
  {name: "Alex", age: 30},
  {name: "Sara", age:20},
  {name: "Mark", age: 13}, 
  {name:"Charlotte", age: 3},
  {name: "Taylor", age: 18}
];
//code here
//this is what I've come up with
var oldEnough=futureStudents.filter(
  function(val){
  if(num.val>=18){
    return futureStudents.name;
  }
});

Open in new window

matt wrightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Snarf0001Commented:
You can use the "=>" shorthand to simplify the code.
And the question is asking for the full record, not just the name.

var futureStudents = [
  {name: "Alex", age: 30},
  {name: "Sara", age:20},
  {name: "Mark", age: 13}, 
  {name:"Charlotte", age: 3},
  {name: "Taylor", age: 18}
];

var oldEnough = futureStudents.filter(student => student.age >= 18);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jan LouwerensSoftware EngineerCommented:
This is where your problem is:
function(val){
  if(num.val>=18){
    return futureStudents.name;
  }

Open in new window


This function should return true for any element that matches the condition, and false otherwise.
It should use the 'val' object, which represents the current value within the array.
You should not be accessing the entire 'futureStudents' array anywhere within that function.

Do these clues help point you in the right direction?
0
matt wrightAuthor Commented:
Thank you so much for your insight and help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.