document.writeln doesn't write to a new line

HTML layout engines fold all whitespace to a single space. Of course you need <br /> or some other mechanism that HTML uses for putting things on separate lines.


document.writeln does this:

Writes a string of text followed by a newline character to a document.

But whitespace is collapsed and converted to a single space when rendering HTML so your newline does nothing inside the HTML.


It just appears to be all on one line. Do this --

document.write('<pre>');
document.writeln(myObject.firstName);
document.writeln(myObject.address[0].Address1);

and you'll see.

Tags:

Javascript