If you mean watchList, then “object array” works but I might say “array of objects” for clarity.
var rating = watchList,map((“title”, “rating”)) => {
return watchList.length == “title” && “rating”;
}
There are some problems here. It should be a period before map, you are passing in the variables wrong, and you are returning the wrong thing.
The map needs the period before it because it is a method, a function that is built into every array. It’s been there all along, you just never used it. This method takes (usually) one parameter: a function (often called a callback function). So you have:
var result = myData.map(myFunction);
That function will process each element in that array add it to a new array that will be returned assigned (in this case) to result.
OK, so how does that function work. Well, map is going to send it some things. It actually sends three things but usually we only care about the first one. We need to “catch” that by naming it. Let’s call it “el” for “element”, but we could have called it “frogSkinPajamas” - JS doesn’t care, we tell it what we’re going to call it. So, we have:
var myFunction = (el) => {
// do stuff
};
So, we catch what’s being sent and call it el. Now we can process each element and do whatever we want to it.
Consider this code:
const people = [
{
firstName: 'Dorthy',
lastName: 'Parker',
quote: 'That woman speaks eighteen languages, and she can’t say "No" in any of them.'
},
{
firstName: 'Robert',
lastName: 'Benchley',
quote: 'I do my best work sitting down; that\'s where I shine.'
},
{
firstName: 'Alexander',
lastName: 'Woollcott',
quote: 'All the things I really like to do are either immoral, illegal or fattening.'
},
];
const newArr = people.map((person) => {
return {
name: person.firstName + ' ' + person.lastName,
quote: person.quote
};
});
I have an array of stuff. I want to create a new array where the first and last names are in one variable instead of two.
So, I map the array of objects people. Into my function I accept a variable that I’ve chosen to call “person”. This will run three times, once for each object in my array. The first time, it will get an object like this:
{
firstName: 'Dorthy',
lastName: 'Parker',
quote: 'That woman speaks eighteen languages, and she can’t say "No" in any of them.'
}
and it will be assigned to the variable person. Then I will immediately return a new object that that has two properties, the new name that I make, and the old quote that I just copy over.
{
name: 'Dorthy Parker',
quote: 'That woman speaks eighteen languages, and she can’t say "No" in any of them.'
}
Where does this new, nameless object go? It goes into the first slot of a new array that will eventually go into the variable newArr. The map method does this for each of the array elements so I end up with a new array of three elements.
Does this make sense?
You need to do something similar in this challenge. You are going to map across watchList. You will get sent each object. You need to create a function that will accept the objects. You need to name the object. Maybe film would be good. You need to create a new object and return it. It says you need a title and rating. If it were the year and genre you needed, you might return something like { year: film.Year, genre: film.Genre }
. Don’t let all the double quotes on the object properties fool you. Since there are no spaces, etc. in the property names, so they didn’t actually need the quotes.
Let us know if this is not enough help.
Yes, this is confusing stuff. Yes, it takes a little while to get the hang of it. It is a different way of thinking, and if you do it over and over, you start to get it. Just keep with it.