Tutorials Point


  JavaScript Basics
  JavaScript Objects
  JavaScript Advanced
  JS Useful References
  JS Useful Resources
  Selected Reading

Copyright © 2014 by tutorialspoint



  Home     References     Discussion Forums     About TP  

Javascript String - split() Method


previous next AddThis Social Bookmark Button


Advertisements

Description:

This method splits a String object into an array of strings by separating the string into substrings.

Syntax:

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

Here is the detail of parameters:

  • separator : Specifies the character to use for separating the string. If separator is omitted, the array returned contains one element consisting of the entire string.

  • limit : Integer specifying a limit on the number of splits to be found.

Return Value:

  • The split method returns the new array. Also, when the string is empty, split returns an array containing one empty string, rather than an empty array.

Example:

<html>
<head>
<title>JavaScript String split() Method</title>
</head>
<body>
<script type="text/javascript">

var str = "Apples are round, and apples are juicy.";

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

document.write( splitted );

</script>
</body>
</html>

This will produce following result:

Apples,are,round, 

To understand it in better way you can Try it yourself.



previous next Printer Friendly

Advertisements


  

Advertisements