Q:

How to find last space of a string using JavaScript and replace it with ` `?

How to find last space of the para using JavaScript and replace it with &nbsp;?
<p class="no-space">Web Development Reading List</p>
(The space between the words "Reading" and "List" to be removed and want to have $nbsp; in place of that. 
ie, Reading&nbsp;List

A:

Use a replace with Regexp:
Using ID

var noSpace = document.getElementById("noSpace");
noSpace.innerHTML = noSpace.innerHTML.replace(/ (?=[^ ]*$)/i, "&amp;nbsp;");
<p class="no-space" id="noSpace">Web Development Reading List</p>

Using class name:

var noSpace = document.getElementsByClassName("no-space");
for (var i = 0; i < noSpace.length; i++) {
    noSpace[i].innerHTML = noSpace[i].innerHTML.replace(/ (?=[^ ]*$)/i, "&amp;nbsp;");
}
<p class="no-space">Web Development Reading List</p>
<p class="no-space">Web Development Reading List</p>
<p class="no-space">Web Development Reading List</p>

You can change &amp;nbsp; to "&nbsp;" if you need the character instead of the string.

