In this post, we will learn how to explode or split a string in JavaScript. So how we can do this, we will learn in this post.  


How To Explode Or Split A String In JavaScript ?


Explode Or Split A String

If we want to explode or split string from a specific character or separator then we we can use the JavaScript  split()  method. So how we can use this method, we will see it in the example below.


<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How To Explode Or Split A String In JavaScript ?</title>
</head>
<body>

<div id="showResult"></div>

<script>

var str = "CodexRadar is a website where you get free codes, tutorials and news.";


// Using split method
var strArray = str.split(" ");

// Variables
var i;
var strValues = "";

// Get all string values with for loop
for(i = 0; i < strArray.length; i++){
strValues += "<p>" + strArray[i] + "</p>";
}

document.getElementById("showResult").innerHTML = strValues;

</script>
</body>
</html> code-box


Summary

In this post we learned how to explode or split a string in JavaScript. You try to make it yourself. I hope you make. If you face any problem, then comment and tell us. Keep visiting the blog to read more similar posts.  

Post a Comment

Previous Post Next Post