数组排序01

arr1 = ["A1", "A2", "B1", "C1", "D1"]
arr2 = ["A", "B", "C", "D"]
将arr1和arr2拼接成arr
arr = ["A1","A2","A","B1","B","C1","C","D1","D"]

let arr1 = ["A1", "A2", "B1", "C1", "D1"]
let arr2 = ["A", "B", "C", "D"]
let arr = []
        let c = 0
        for (let i = 0; i < arr2.length; i++) {
            for (let k = c; k < arr1.length; k++) {
                if (arr1[k].startsWith(arr2[i])) {
                    arr.push(arr1[k])
                    c++
                } else {
                    arr.push(arr2[i])                   
                    break
                }
            }
        }

你可能感兴趣的:(数组排序01)