Q:

How to explode or split a string in JavaScript

0

How to explode or split a string in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the JavaScript split() method

If you want to explode or split a string from a certain character or separator you can use the JavaScript split() method. The following example will show you how to split a string at each blank space. The returned value will be an array, containing the splitted values.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Split a String from Space</title>
</head> 
<body>
    <script>
        var myStr = "The quick brown fox jumps over the lazy dog.";
        var strArray = myStr.split(" ");
        
        // Display array values on page
        for(var i = 0; i < strArray.length; i++){
            document.write("<p>" + strArray[i] + "</p>");
        }
    </script>
</body>
</html>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to assign block of HTML code to a JavaScript v... >>
<< How to replace character inside a string in JavaSc...