let opArr = [{
id: '1',
name: '的'
}, {
id: '2',
name: '地方'
}, {
id: '3',
name: '好'
}, {
id: '1',
name: '就'
}, {
id: '2',
name: '看'
}, {
id: '1',
name: '解决'
}, {
id: '1',
name: '哈哈哈'
}]
function fac(data, total) {
let count = data.filter(v => {
return v.id === '1'
})
if (count.length === 1) return [data, ...total];
let _data = data.splice(0, data.indexOf(count[count.length - 1]));
return fac(_data, [data, ...total]);
}
let count = fac(opArr, []);
console.log(count)
来源:https://www.cnblogs.com/lgjc/p/12574272.html