Answers for "print js object"

5

print object in javascript

str = JSON.stringify(obj);
str = JSON.stringify(obj, null, 4); // (Optional) beautiful indented output.
console.log(str); // Logs output to dev tools console.
alert(str); // Displays output using window.alert()
Posted by: Guest on May-05-2020
0

print an object in javascript

<p id="demo"></p>

<script>
const person = {
  name: "John",
  age: 30,
  city: "New York"
};

document.getElementById("demo").innerHTML = JSON.stringify(person);
</script>

result:
Display properties in JSON format:

{"name":"John","age":30,"city":"New York"}
Posted by: Guest on March-07-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language