March 2018
Intermediate to advanced
592 pages
13h 44m
English
The first thing we need to do is try to find a match and I'm going to use the array find method to get that done. We'll create a const user to store the match, then we'll set it equal to users.find, passing in our function:
const getUser = (id) => { return new Promise((resolve, reject) => { const user = user.find(() = { }); });};
Now this function gets called one time for every item in the array. It's an array of users so we can call the individual item user. If we return true, it is going to consider that a match. It'll stop and it'll set that object on a user. If we return false, it'll continue on through the array and, if none are matched, undefined will be the value for user. So, we're just going to return