How to use Split in JavaScript

In this article we will discuss about how to use Split() Method in JavaScript.
  • 2316

The Split method works with the strings in JavaScript. This method split an String object into substring separated by the comma. Split method work as a separator to divide a string into substring. Here is the syntax to define it.

Syntax:

string.split ([seperator] [, limit]);

In this separator specifies which character will be use to separate the string in to substring and limit specifies the integer number which further specifies the number of splits to be displayed or found.

Lets have a look on the following example:

<html>

<head>

<title>JavaScript String split() Method</title>

</head>

<body>

<script type="text/javascript">

 

    var str = "Earth is round, and Moon is round.";

 

    var splitted = str.split(" ", 5);

 

    document.write(splitted);

 

</script>

</body>

</html>

Output:

earth.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.