String Function split()
Method or Function: split(argument)
Syntax: String.split(arg)
Split function takes one argument called delimiter.
Every part of the string that comes in between the delimiter is separated as a string.
A delimiter can be any string or a character or even blank space.
Example: 1
<script type="text/javascript">
var a = "split-function-test";
document.write(a.split("-"));
</script>
var a = "split-function-test";
document.write(a.split("-"));
</script>
Here we pass delimiter argument as ‘-‘ sign.
Example: 2
<script type="text/javascript">
var a = "split+function+test";
document.write(a.split("+"));
</script>
var a = "split+function+test";
document.write(a.split("+"));
</script>
Here we pass delimiter argument as ‘+’ sign.
Example: 3
<script type="text/javascript">
var a = "split function test";
document.write(a.split(" "));
</script>
var a = "split function test";
document.write(a.split(" "));
</script>
Here we pass delimiter argument as blank space.
No comments:
Post a Comment