JavaScript To Split The Words or Concatenated Word

<html>
<body>
First Word:-Hello<br/>
Second Word:-world!<br/>

<button onclick=”myFunction()”>Click To Split</button><br/>
<pre>Concatenation:-<p id=”orgi”></p><br/>
First Word:<p id=”demo”></p>
Second Word:<p id=”demo1″></p>

<script>
function myFunction() {
var str1 = “Hello”;
var str2 = “world!”;
var res = str1+”$|$”+str2;
document.getElementById(“orgi”).innerHTML = res;
var res1 = res.split(“$|$”)[0];
var res2 = res.split(“$|$”)[1];

document.getElementById(“demo”).innerHTML = res1;
document.getElementById(“demo1”).innerHTML = res2;
}
</script>

</body>
</html>

Snapshot:-

 

 

——————————————————