美文网首页
for in常用于Object,而要遍历Array最好还是用fo

for in常用于Object,而要遍历Array最好还是用fo

作者: Kawing_Zhang | 来源:发表于2018-12-20 15:12 被阅读0次

for in常用于Object,而要遍历Array最好还是用for of

//for of 

for(let items of productsData){

            for(let item of items.products){

                if(item.id == id){

                    this.setData({ product: item });

                }

            }

        }


//for in 在这里失效了,遍历出来的items 只有对应的下标index

for(let items of productsData){

            for(let item of items.products){

                if(item.id == id){

                    this.setData({ product: item });

                }

            }

        }

相关文章

网友评论

      本文标题:for in常用于Object,而要遍历Array最好还是用fo

      本文链接:https://www.haomeiwen.com/subject/qjvykqtx.html