對象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