I am trying to display/append my Java script object on the webpage. I want to display each key and it's corresponding value.
Most of the questions that are similar to mine only have answers that suggest to log it to the console or alert it. Unfortunately, this is not what I want.
I have also tried JSON.stringify()
, however this seems to just display a blog of text. If JSON.stringify()
is the only way to print/output the objects key/values pairs to the document, is there anyway to style it?
The following is some that I have tried but with no prevail.
JSON.stringify(object, null, 4));
object.__proto__.toString();
Here is an example of what I want:
Name: John
Name: Bob
Name: Thomas
Without any JSON
format curly brackets or any other formatting. Just plain text.
EDIT: I am indeed familiar with document.write()
, this is not a solution. I need to APPEND to a web page that already has content, the key and value pairs of my Javascript object.
The Javascript object is dynamic and has a unknown length.
Something like this:
$('#container').html(object);
$('#container').append(object);