为什么没在循环里的console.log也会循环,不是只执行一次嘛

新手上路,请多包涵
const arr = [1, 2, 3, ["a", "b", "c"]];
    function a(params) {
        for (const iterator of params) {
            if (typeof iterator === "object") {
                a(iterator);
        }
        console.log(params);
    }
    a(arr);
阅读 1.9k
2 个回答

因为for 循环多次满足条件,所以会多次进行console.log打印,而且代码少了个 '}'

仔细看代码,你的缩进搞错了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题