Reputation: 21999
I am trying to check if a string is contained in another string. Code behind is pretty straight forward. How can I do that in jquery?
function deleteRow(locName, locID) {
if(locName.Contains(locID)) {
alert("success");
}
}
Upvotes: 0
Views: 445
Reputation: 324627
You can use the indexOf
method of the string. If you really want the convenience of having a contains
method, you could add one to String.prototype
:
String.prototype.contains = function(str) {
return this.indexOf(str) > -1;
};
alert("foobar".contains("oob")); // true
alert("foobar".contains("baz")); // false
Upvotes: 1
Reputation: 13756
you can use indexOf if the string is found returned result will be different from -1
function deleteRow(locName, locID) {
if(locName.indexOf(locID) != -1) {
alert("success");
}
}
I hope this helps
Upvotes: 0
Reputation: 169451
For example: (locName.indexOf(locID) > -1)
String.prototype.contains doesn't exist.
Upvotes: 9