hi i want to a one line of code (without using loop) in javascript to find the if there is semicolon in a string... please help if any one knows
2 Answers 2
myStringVal.indexOf(";") !== -1;
For more information, check out the documentation for String.prototype.indexOf() .
answered May 6, 2011 at 14:15
canon
41.8k10 gold badges77 silver badges102 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
T.J. Crowder
+1 (although I always advocate
>= 0 rather than != -1 out of paranoia; but the spec does specifically say -1 for not found, so...) But please refer people to the specification. w3schools is incomplete at best.if (stringvalue.indexOf(";") >= 0) {
alert("String value contains semi colon");
}
answered May 6, 2011 at 14:16
Sang Suantak
5,2652 gold badges30 silver badges46 bronze badges
Comments
lang-js