function moveElementsToEnd(arr, value) {
// 将不符合条件的元素保留,并移动到数组末尾
arr = arr.filter(item => item !== value).concat(arr.filter(item => item === value));
return arr;
}
// 示例使用
const myArray = [1, 'a', 'b', 'c', 2, 3, 'd', 4];
const valueToMove = 'b';
const resultArray = moveElementsToEnd(myArray, valueToMove);
console.log(resultArray); // 输出: [ 'a', 'c', 'd', 1, 2, 3, 4, 'b' ]
所有等于字符串'b'
的元素被移动到了数组的末尾。其他元素保持原位置不变。