I'm trying to turn this array into 2 different arrays. One array should be of names that contain the letter 'o' in them and the second array should be the rest of the names, that do not have 'o'.
I can only use the for loop and the only method I can use is .push().
Given array:
var names = ['octavia', 'peter', 'olive', 'ava', 'aiden'];
Desire result:
var nameO = ['octavia', 'olive'];
var nameNoO = ['peter', 'ava', 'aiden'];
This is the code I came up with. Got one of the results for names with 'o', but not without 'o'.
var names = ['octavia', 'peter', 'olive', 'ava', 'aiden'];
var namesO = [];
var namesNoO = [];
for(let i in names){
for(let j in names[i]){
if(names[i][j] === 'o'){
namesO.push(names[i]);
}
if(names[i][j] !== 'o'){
namesNoO.push(names[i])
}
}
}
console.log(namesO, namesNoO);
if(names[i][j] !== 'o')pushes all names that have at least one character different fromointo thenoOarray. For your approach to work, you have to go through the complete name, and only if noowas found, add it to thenoOarray