I have developed a simple system that identifies users with matching genre interests as a specific user. I am trying to store the results of the for loop in an array, but currently only the last output is being added. I want all matching results to be included in the array. Any suggestions?
// User database
var jon = {username: 'Jon', genrePref: 'Rock'};
var lucy = {username: 'Lucy', genrePref: 'Pop'};
var mike = {username: 'Mike', genrePref: 'Rock'};
var luke = {username: 'Luke', genrePref: 'House'};
var james = {username: 'James', genrePref: 'House'};
var dave = {username: 'Dave', genrePref: 'Bass'};
var sarah = {username: 'Sarah', genrePref: 'Country'};
var natalie = {username: 'Natalie', genrePref: 'Bass'};
//userProfile.push()
// User database array
var userProfile = [jon, lucy, mike, luke, james, dave, sarah, natalie];
// Object containing username of logged in user and specification of the loaded track's genre
var trackGenre = {username: 'Harry', trackGenre: 'Rock'};
// For loop listing usernames of users with genre preference matching the distributed track
for(i = 0; i < userProfile.length; i++){
if(userProfile[i].genrePref == trackGenre.trackGenre){
console.log(userProfile[i].username);
var matches = [];
matches.push(userProfile[i].username);
}
}
console.log(matches)