I'm trying to find the even length strings of a function that will take an array of values, and I should then return an array of all the even length strings.
Anything that's not a string, or not a string of even length, should not be returned in the array.
If there are no even length strings, it should return an empty array.
I've managed to return an empty array when passed an empty array, keep even length strings, remove odd length strings and removes non-strings. However, when given multiple strings that are even it only gives the first one. For example, for the function findEvenLengthStrings(["dogs", "cats"]) it only gives "dogs" but doesn't give cats.
Been working on this for a while and can't find simular questions. I also only understand for loops at this point so an array reduce may confuse me.
Here is my code so far!
function findEvenLengthStrings(items) {
let empty = []
let evenLength = []
for (let i = 0; i < items.length; i++) {
if (items[i].length % 2 === 0) {
evenLength.push(items[i])
}
return evenLength
}
return empty
}