24
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

連想配列をコンソールで深い階層の中身も全部表示する

Posted at

node.jsでサーバーを立てておいて、ブラウザでjavascriptを書く際と同じような感覚で連想配列(オブジェクト)を

script.js

console.log(obj);

って感じで表示しようとすると、配列が2階層以上あるものは

{ 
  text: 'aaaa',
  arrayObj: [ Array ]
}

このように中身が省略されてしまいます。ブラウザの場合はこのArrayを更に展開できますが、コンソールではできません。

ということで

script.js
console.log(JSON.stringify(obj,null,'\t'));

とすれば

{ 
  text: 'aaaa',
  arrayObj:
   [ { text: 'bbb',
       arrayContent: ['a','b','c'] },
     { text: 'ccc',
       arrayContent: ['d','e','f'] },
}

という感じに階層が深くても中身が全部表示されるようになりました。

めでたしめでたし。

24
19
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
19

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?