SOURCE

let arr1 = [1, 2, 3, 4];
let arr2 = [1, 2];
let e1 = arr1.length - 1;
let e2 = arr2.length - 1;
let i = 0;

while (i <= e1 && i <= e2) {
    let num1 = arr1[i];
    let num2 = arr2[i];

    if (num1 != num2) {
        break;
    } else {
        i++;
    }
}

while (i <= e1 && i <= e2) {
    let num1 = arr1[e1];
    let num2 = arr2[e2];

    if (num1 != num2) {
        break;
    } else {
        e1--;
        e2--;
    }
}
console.log(i);
console.log(e1, e2)
if (i > e1) {
    if (i <= e2) {
        while (i <= e2) {
            arr1.splice(i, 0, arr2[e2]);
            i++;
        }
    }
}
else if (i > e2) {
    while (i <= e1) {
        arr1.splice(i, 1);
        i++;
    }
}
console.log(arr1)
console 命令行工具 X clear

                    
>
console