对于一个项目,我必须对包含字符串和数字的数组进行排序。该字符串用作应将数字存储到哪个数组中的指示符。
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 {}
}
预期结果 :
talk [22, 42], perfo [35], init [42]
但不知何故,它似乎甚至没有通过 for 循环。
MYYA
慕无忌1623718
相关分类