Download presentation
Presentation is loading. Please wait.
Published byHamdani Pranata Modified over 6 years ago
1
String, Math & Miscellaneous Methods & Properties
© 2006 D. J. Foreman
2
String Object Methods & Properties
anchor( ) big( ) blink( ) bold( ) charAt( ) fontcolor( ) fontsize( ) indexOf( ) italics( ) lastIndexOf( ) link( ) small( ) sub( ) sup( ) substr(start, length) substring(start, end) toLowerCase( ) toUpperCase( ) length is a property of a string - so, no ( ) © 2007 D. J. Foreman
3
Example: indexOf Purpose: locate a string in another string
Let x be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman" We want to see if it contains an "F" J = x.indexOf("F"); J now has the position of the "F" Remember that we start counting at ZERO So J now has the value of 3 © 2007 D. J. Foreman
4
Example: lastindexOf, length
<html> <script language="javascript"> X="DJ Foreman, Ph. D."; document.write(X.lastIndexOf(" ")+"<br>"); document.write(X.length); </script> </html> Result is: © 2007 D. J. Foreman
5
Example of substr Purpose: copy a piece of a string, given its start and length Let X be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman, Ph. D." If we want the "Foreman": M=X.indexOf(" ")+1; // finds the 1st char after the blank N=X.indexOf(","); // finds the comma L=N-M; // computes the length Y=X.substr(M, L); // gets the "Foreman" into Y © 2007 D. J. Foreman
6
Example of substring Purpose: copy a piece of a string, given its start and ending position Let X be a string variable (maybe from some kind of input operation) that currently has the value: "DJ Foreman, Ph. D." If we want the "Foreman": M=X.indexOf(" ")+1; // finds the 1st char after the blank N=X.indexOf(","); // finds the comma Y=X.substring(M,N); // gets the "Foreman" into Y © 2007 D. J. Foreman
7
Some Math Object Methods
abs( ) ceil( ), floor( ) exp( ) log( ) max( ), min( ) pow( ) random( ) round( ) sqrt( ) sin(radians), asin( ) cos( ), acos( ) tan( ), atan( ) © 2007 D. J. Foreman
8
Some Math Object Properties
LN2, LN10 LN2E, LOG2E PI SQRT2 SQRT1_2 (sqrt of 1/2) ex: Math.PI These are all constants © 2007 D. J. Foreman
9
Some Misc Methods blur( ) focus( ) select( ) eval( )
parseInt( ) or ParseFloat( ) if var x="10"; y="5"; x+y gives "105" parseInt(x)+parseInt(y) gives 15 © 2007 D. J. Foreman
10
Some Useful References
"Javascript by Example" (various publishers, if you can find it) "How to Set Up and Maintain a WWW Site", Addison Wesley "Essential Javascript for Web Professionals", Prentice Hall "Essential CSS & DHTML for Web Professionals", Prentice Hall © 2007 D. J. Foreman
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.