Avatar of matt wright
matt wright

asked on 

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

JavaScript

Avatar of undefined
Last Comment
matt wright
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
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?
Avatar of matt wright
matt wright

ASKER

Thank you so much for your insight and help.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo