I am trying to understand the difference between these 2 methods. Consider an array of objects as follows:
var newReleases = [ { "id": 70111470, "title": "Die Hard", }, { "id": 654356453, "title": "Bad Boys", }, { "id": 65432445, "title": "The Chamber", }, { "id": 675465, "title": "Fracture", } ]; return newReleases. filter(function(video) { return video.rating === 5.0; }). map(function(video) { return video.id; });
So, from what I have understood, filter only filters items of an array based on the given condition. So, it returns an array with objects/items that fulfill the particular condition(in this case, movies with ratins equal to 5.0) and map returns only that particular property within each object (such as id) as an array.
Am I correct in my understanding of maps and filters? Working with an array of objects is more confusing than just an array with plain items.