遍历DOM打平
html 模板
<div class="box">
<p>1</p>
<p>2</p>
<div>
<p>a</p>
<p>b</p>
</div>
<div>
<p>x</p>
<p>y</p>
<div>
<span>asd</span>
</div>
</div>
</div>
js
let l = console.log
let box = document.querySelector('.box')
let toArray = Array.from;
scan(box)
function scan(box) {
let arr = toArray(box.children)
for (let ele of arr) {
if (ele.children.length) {
scan(ele)
}else{
l( ele)
}
}
}