Here is my code :
var string1= "Hello how are =you";
I want a string after "=" i.e. "you" only from this whole string. Suppose the string will always have one "=" character and i want all the string after that character in a new variable in jquery.
Please help me out.
Use this : jQuery split(),
var string1= "Hello how are =you";
string1 = string1.split('=')[1];
Split gives you two outputs:
[0]
= "Hello how are "
[1]
= "you"
Try to use String.prototype.substring()
in this context,
var string1= "Hello how are =you";
var result = string1.substring(string1.indexOf('=') + 1);
Proof for the Speed in execution while comparing with other answers which uses .split()
use Split
method to split the string into array
demo
var string1= "Hello how are =you";
alert(string1.split("=")[1]);
Use .split()
in javascript
var string1= "Hello how are =you";
console.log(string1.split("=")[1]); // returns "you"
Demo
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