forEach is not a function error with JavaScript array

前端 未结 11 572
梦毁少年i
梦毁少年i 2020-11-29 17:11

I\'m trying to make a simple loop:

const parent = this.el.parentElement
console.log(parent.children)
parent.children.forEach(child => {
  console.log(chil         


        
11条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 17:51

    A more naive version, at least you're sure that it'll work on all devices, without conversion and ES6 :

    const children = parent.children;
    for (var i = 0; i < children.length; i++){
        console.log(children[i]);
    }
    

    https://jsfiddle.net/swb12kqn/5/

提交回复
热议问题