1 start下标实现往固定地方插入数据
const aa = [1, 2, 3, 4, 5, 6];
let bb = [
{ start: 5, list: ['b1', 'b2', 'b3'] },
{ start: 0, list: ['a1', 'a2'] },
{ start: 1, list: ['c1', 'c2'] },
{ start: 1, list: ['c11', 'c22'] },
{ start: 2, list: ['d1', 'd2'] },
{ start: 3, deleteCount: 1 },
];
bb.sort((a, b) => {
return a.start - b.start;
});
let count = 0;
bb.forEach((b) => {
const { start, deleteCount = 0, list = [] } = b;
aa.splice(start + count, deleteCount, ...list);
count += list.length - deleteCount;
});
console.log(aa);