Languages

JavaScript - equivalent of var_dump or print_r in PHP?

0 points
Asked by:
Reilly-Collier
860

I've created an object in JavaScript and I would like to see its methods/fields for debugging.

Is there anything similar to var_dump in PHP?

1 answer
0 points
Answered by:
Reilly-Collier
860

Use console.log() method that outputs a message to the web console.

However, to display objects in the console you will also need convert them to the string first using JSON.stringify() method.

Practical example

// ONLINE-RUNNER:browser;

var object = { id: 1, name: 'Tom' };

console.log(JSON.stringify(object));

 

See also

  1. JavaScript - print object in console

References

  1. console - Web APIs | MDN 
0 comments Add comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join