对象object在console.log时,显示[Object]的解决方案


平时工作中,时常要打印一些对象到控制台,但平常的console.log只能看到最外的一层,里边的都会以[Object]隐藏掉 如:

[ { id: '300760', data: [ [Object], [Object] ] },
  { id: '300529',
    data:
     [ [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object],
       [Object] ] },
 ]

可以用console.dir(object, {depth:null}} 来显示全部

[ { id: '300760',
    data:
     [ { code: '300760', season: '2018-12-31', profit: 369067 },
       { code: '300760', season: '2019-12-31', profit: 461498 } ] },
  { id: '300529',
    data:
     [ { code: '300529', season: '2011-12-31', profit: 7100 },
       { code: '300529', season: '2012-12-31', profit: 9361 },
       { code: '300529', season: '2013-12-31', profit: 12099 },
       { code: '300529', season: '2014-12-31', profit: 14566 },
       { code: '300529', season: '2015-12-31', profit: 19390 },
       { code: '300529', season: '2016-12-31', profit: 19413 },
       { code: '300529', season: '2017-12-31', profit: 24517 },
       { code: '300529', season: '2018-12-31', profit: 35224 },
       { code: '300529', season: '2019-12-31', profit: 52199 } ] },
 ]

可以看到相当pretty了

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM