function removeElements(arr, valueToRemove) {
let i = arr.length;
while (i--) {
if (arr[i] === valueToRemove) {
arr.splice(i, 1);
}
}
return arr;
}
// 示例用法
let myArray = [1, 2, 3, 4, 2, 5];
let newValue = 2;
removeElements(myArray, newValue);
console.log(myArray); // Output: [1, 3, 4, 5]