I have a variable var i = "my*text"
I want to split it using special character *
. I mean, I want to generate var one
= "my" and var two
= "text" from the above variable.
How can I do this using jQuery and (or) JavaScript? .
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
In JavaScript you can add special characters to a text string by using the backslash sign.
delimiter. Optional. It is delimiter used to break the string into the array of substrings. It can be a single character, string or regular expression. If this parameter is not provided, the split() method will return an array with one element containing the string.
In that case, the split() method returns an array with the entire string as an element. In the example below, the message string doesn't have a comma (,) character.
values=i.split('*'); one=values[0]; two=values[1];
use string.split(separator, limit)
<script type="text/javascript"> var str="my*text"; str.split("*"); </script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With