OneCompiler

How to display a JavaScript object?

I am trying to display the content of a JavaScript object, but it's always printing [object Object] Instead of the data. How to print the data?

1 Answer

5 years ago by

You can use the native JSON.stringify() method to convert a JSON into a string.

str = JSON.stringify(obj)
console.log(str)
5 years ago by Divya