二维数组展平为一维数组
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>二维数组展平为一维数组</title>
</head>
<body>
<script type="text/javascript">
function simpleNormalizeChildren(children) {
for(let i = 0; i < children.length; i++) {
if(Array.isArray(children[i])) {
return Array.prototype.concat.apply([], children)
}
}
return children
}
console.log(simpleNormalizeChildren([1, [2, 3]]))
</script>
</body>
</html>
作者:孟繁贵 Email:meng010387@126.com 期待共同进步!