function findAllOccurrences(arr, target) { let position = []; for(let i = 0; i < arr.length; i++){ if(arr[i] === target){ position.push(i) } } return position }
注意:let position = [] 数组的设定要放在for循环外面,常见放在里面的错误,要注意;return position同样要放for循环外面。