As part of a project, I am required to organize this array that includes both strings and numbers. The strings act as indicators for which array the number should be stored in.
let myArray = [22, 'talk', 31, 'perfo', 35, 'init', 42, 'talk']
let talk = []
let perfo = []
let init = []
for (let i = 0; i < myArray.length; i + 2) {
if (myArray[i + 1] == 'talk') {
talk.push(myArray[i])
} else if (myArray[i + 1] == 'perfo') {
perfo.push(myArray[i])
} else if (myArray[i + 1] == 'init') {
init.push(myArray[i])
} else {}
}
The expected output should be:
talk [22, 42], perfo [35], init [42]
However, it appears that the for loop is not being executed properly.