Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the JavaScript equivalent of Ruby's "inspect"?

In Ruby, you can do foo.inspect and it outputs something sane for any object pretty much regardless of type.

How do I achieve the same thing in JavaScript?

like image 400
Lee Avatar asked Oct 09 '10 20:10

Lee


2 Answers

JSON.stringify(foo) works pretty well.

like image 107
Michaël Witrant Avatar answered Sep 20 '22 11:09

Michaël Witrant


This is possibly not the entirely general answer you're hoping for, since this introduces third-party dependencies into you application. However, they're worth mentioning:

  • For applications using Prototype (link) you can use Object.inspect (link)
  • For applications using jQuery (link) there's the jquery-inspect (link) plugin
like image 33
Richard Cook Avatar answered Sep 17 '22 11:09

Richard Cook