Eg: For converting the given string into upper case & Lower case: <html> <body> <script type = "text/javascript"> <var name = "Microsoft"> document.write("Number of characters are " +name.length +"<br>") document.write(name.toUpperCase() +"<br>") document.write(name.toLowerCase() +"<br>") </script> </body> </html> Output: Number of characters are 9 MICROSOFT microsoft
Eg: For searching string within the given string: <html> <body> <script type = "text/javascript"> var city = "Hyera bad" document.write(city.match("bad") +"<br>") document.write(city.match("badh") +"<br>") document.write(city.match("Bad") +"<br>") document.write(city.match(" bad") +"<br>") </script> </body> </html> Output: bad null null bad
Eg:For indexOf(): <html> <body> <script type = "text/javascript"> var city = "Hyera bad" document.write(city.indexOf("bad") +"<br>") document.write(city.indexOf("Hydera ") +"<br>") document.write(city.match("Bad") +"<br>") document.write(city.match(" bad") +"<br>") </script> </body> </html> Output: 7 0
Eg: For styles of strings: 1.big() 2.small() 3.bold() 4.Italic() 5.blink() 6.strike() 7.fontcolor("red") 8.fontsze(16) 9.sup() 10.sub() 11.link("http://www.microsoft.com")
Date Object: Date is pre-defined java script object, it holds the current date & time information.
Eg: To display the current date & time by using date pre-defined object: <html> <body> <script type = "text/javascript"> document.write(Date()) </script> </body> </html> Output: THU DEC 22 19:35 2010 Synatax:to create a user defined date object: var mydate = new Date() (Here, "mydate" is a user defined date object and "Date()" is a pre-defined date object)
Eg: To display the current date & time by using user defined date object: <html> <body> <script type = "text/javascript"> var mydate = new Date() document.write(mydate) </script> </body> </html> Output: THU DEC 22 19:35 2010
Eg: To assign a particular date to user defined date object: <html> <body> <script type = "text/javascript"> var mydate = new Date() mydate.SetFullYear(2014,0,26) document.write(mydate) </script> </body> </html> Output: SUN JAN 26 19:35 2010
SetFullYear: Using this pre-defined method we can assign some date to user define date object.
Syntax for SetFullYear: <dateobeject>.SetFullYear(YYYY,MM,DD)
Eg: To add 15 days to current date: <html> <body> <script type = "text/javascript"> var mydate = new Date() mydate.setDate(mydate.getDate()+15) document.write(mydate) </script> </body> </html> Output: FRI JAN 7 19:35:14 UTC+ 2011
setDate: Using this method we can add or set some date to date object.
getDate: This method will pick the only date from user defined date object.
Eg: To add 7 days to 2014, DEC 25 <html> <body> <script type = "text/javascript"> var mydate = new Date() mydate.SetFullYear(2014,11,25) mydate.setDate(mydate.getDate()+7) document.write(mydate) </script> </body> </html> Output: mydate 2014, 11, 25 2015, 0, 1