JAVASCRIPT

 Home  Computers & Internet  Web Programming JAVASCRIPT
What is Javascript?
Javascript Placement
Syntax
Reserved Words
Variables
Data Types
Escaping Characters
Concatenation
Arithmetic Operators
Assignment Operators
Comparison Operators
Boolean Operators
Conditional Operator
If Statements
Else If Statements
If Else Statements
Switch Statements
While Loops
For Loops
Do While Loops
Break Statement
Continue Statement
prompt()
alert()
Date()
Event Handlers
String Object Methods
Math Object Methods
Window Object Methods
Arrays

JAVASCRIPT search() METHOD

The search() method searches a string for specified character/s. Returns the position if found or -1 if not found.

The search() method takes one compulsory argument: the string or character tosearchfor. (Always remember that the first position of a string always starts at 0 and not 1).

The general format is:

string.search(/tosearchfor/);

Please note:

The tosearchfor argument must be enclosed in two forward slashes like: /tosearchfor/

By default, the search() method is case sensitive. To make it case insensitive place an i after the second forward slash like:

string.search(/tosearchfor/i);

Example: Default Search - case sensitive

<script type="text/javascript">

var string="The brown box is brown";

document.write(string.search(/brown/));

</script>

The above will output:



Example: Case Insensitive

<script type="text/javascript">

var string="The Brown box is brown";

document.write(string.search(/brown/i));

</script>

The above will output:





See Also:

anchor() big()
blink() bold()
charAt() charCodeAt()
concat() fixed()
fontcolor() fontsize()
fromCharCode() indexOf ()
italics () lastIndexOf()
link() match()
replace () search()
slice() small()
split() strike()
sub() substr()
substring() sup()
toLowerCase() toUpperCase()
toSource() valueOf ()

Home | Privacy Policy | Terms Of Use | Contact Us