Parsing filtered data from array

I am stuck trying to parse de final data, how am I supposed to combine this within the filter function.

Thank you!

Your code so far

WARNING

The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.

You will need to take an additional step here so the code you wrote presents in an easy to read format.

Please copy/paste all the editor code showing in the challenge from where you just linked.

const filteredList = watchList.map(movies => {
  return {
    title: movies.Title,
    imdbRating: movies.imdbRating
  }
})
const greatRating = filteredList.filter(movies => movies.imdbRating >= 8.0) 

// Only change code above this line

console.log(greatRating);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0

Challenge: Use the filter Method to Extract Data from an Array

Link to the challenge:

  1. The rating property is supposed to be named rating and not imdbRating

  2. The final array is supposed to be assigned to the filteredList variable (change the map array name and use the filteredList name for the final filtered array instead).

thank you, I did change that but I am still getting an error, I think it is a parsing error

const filteredList = watchList.map(movies=>{
  return {
    Title: movies.Title,
    rating: movies.imdbRating
  }
});

filteredList.filter(movies=> movies.imdbRating >= 8.0)

You are still filtering on imdbRating and not rating.

Also, you need the array returned from the filter to be assigned to the filteredList variable.

edit: you also change the title property for some reason.

1 Like

yes sorry, I went though multiple rounds of edit trying to get the same output that the excersise wants me to get so far this is what I have and I still do not know how to parse the rating number:

[ { Title: 'Inception', rating: '8.8' },
  { Title: 'Interstellar', rating: '8.6' },
  { Title: 'The Dark Knight', rating: '9.0' },
  { Title: 'Batman Begins', rating: '8.3' },
  { Title: 'Avatar', rating: '7.9' } ]

here is my latest stage and driving myself crazy now

const filteredList = watchList.map(movies=>{
  return {
    Title: movies.Title,
    rating: movies.imdbRating
  }
});

filteredList.filter(movies=> parseInt(movies.rating) >= 8.0)

The first error message I get is:

“Your code should use the filter method”.

You need to use filter and map together in the same statement. The method filter returns an array, so you can’t just call it on an array without saving the returned array. If you aren’t sure how to do this google “javascript method chaining”. Remember, the map method returns a new array and you can definitely use the filter method on any array.

Another issue is that you aren’t using the correct property name for title (capitalization matters).

1 Like

omfg! I can’t believe i just needed to chain the filter right after map without calling watchList again, thank you so much! Problem solved

const filteredList = watchList.map(movies=>{
  return {
    title: movies.Title,
    rating: movies.imdbRating
  }
}).filter(movies=> parseInt(movies.rating) >= 8.0)
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.