Skip to content

Replace new lines with spaces in JavaScript

Find out how to replace new line characters with spaces in JavaScript.

 var sentence = "She\nsells\nshe\nshells\non\nthe\n\sea\nshore";
 sentence = sentence.replace(/\n/g, " ");
console.log(sentence); //She sells she shells on the sea shore
See also  Jewels and Stones - Leetcode Challenge - Python Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.