Given below is the code I have written in attempt to create a function that finds all 4 letters in an array, places them onto a new one, and returns it.
Whenever I tried to run the code below, it doesn't give all the 4 letters names, only the first one.
What is the mistake I am doing?
function friend(friends){
let result = [];
for (let i = 0; i < friends.length; i++){
if (friends[i].length == 4) {
result.push(friends[i]);
return result;
}
}
};
let x = ["Dustin", "Lily", "Steve", "Zed", "Mike"];