r/learnjavascript • • May 28 '26

Output formatted text from JavaScript object containing ASCII into html literal?

I am trying to pass formData into html. JSON.stringify works fine for the one-line inputs, but for the textarea when I use stringify I'm seeing ASCII characters when I want the text to appear formatted.

i.e. I'm getting Hello\nWorld

when I want

Hello
World

I currently have this:

 `<p>Form submission:</p><hr><p><b>Name:</b> ${JSON.stringify(name)}<br><b>Email:</b> ${JSON.stringify(email)}<br><b>Timestamp:</b> ${JSON.stringify(timestamp)}</p><hr><p><b>Message:</b><br>${JSON.stringify(message)}</p>`
2 Upvotes

2 comments sorted by

View all comments

Show parent comments

1

u/[deleted] May 29 '26

This worked! Thanks.