String split()
split() separates the string into an array of substrings based on a separator. The separator may be a string or a RegExp object.
An optional second argument sets the array limit. It ensures that the returned array will be no larger than a certain size.
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
<script type="text/javascript">
var colorText = "A,B,C,D";
var colors1 = colorText.split(","); //["A", "B", "C", "D"]
document.writeln(colors1);
var colors2 = colorText.split(",", 2); //["A", "B"]
document.writeln(colors2);
var colors3 = colorText.split(/[^\,]+/); //["", ",", ",", ",", ""]
document.writeln(colors3);
</script>
</head>
<body>
</body>
</html>
Home
JavaScript Book
Essential Types
JavaScript Book
Essential Types
String:
- The String Type
- String length property
- String charAt()
- String charCodeAt()
- String concat()
- String slice()
- String substr()
- String substring()
- String indexOf()
- String lastIndexOf()
- String trim() Method
- String toLowerCase()
- String toLocaleLowerCase()
- String toUpperCase()
- String toLocaleUpperCase()
- String match()
- String search()
- String replace()
- String split()
- String localeCompare() Method
- String fromCharCode() Method
- String HTML Methods