Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Array Iteration Methods Array Manipulation Practice filter()

how do I properly return this new array?

need help with this challenge. I've gotten this far but I definitely know something isn't quite right with my return statement, do I need to use [] at all there?

const years = [1989, 2015, 2000, 1999, 2013, 1973, 2012];
let century20;

// century20 should be: [1989, 2000, 1999, 1973]
// Write your code below
 century20 = years.filter (year => {
  if (year.index <= 2000) {
    return century20[year];


1 Answer

Emmanuel C
Emmanuel C
10,636 Points

Hey Cole,

So, filter takes a function as a parameter that is applied to each item in the array. When you create the arrow function with year as a parameter. year is the item in the years array. So doing year.index would be like doing 1989.index, in the first iteration.

Also, what returns from that inner function should be a boolean(true/false) as to whether that year item passes the condition it's supposed to be filtered by. Basically, just checking and returning if the year <= 2000 is what that inner function is supposed to do. Something like this...

 century20 = years.filter(year => { return (year <= 2000) });

You can shorten is further with arrow functions by removing the curly braces, the return, and the parenthesis too if you'd like. Like...

 century20 = years.filter(year => year <= 2000);

alright this makes sense now, my code was saying to iterate down from 2000 not the whole list. thanks for the help!