What is an object
All things in JavaScript are objects: strings, numbers, arrays, functions ....
Each object has properties and methods
JavaScript allows custom objects
Custom Objects
Defining and creating an object instance
Use a function to define an object, and then create a new object instance
String String Object
String object to handle an existing string
strings can use single or single quotation marks
Find string in string: IndexOf ()
Content matching: Match ()
Replacement content: replace ()
String Case conversion: toUpperCase ()/tolowercase ()
String conversions to Arrays: Strong>split ()
String properties and methods:
1 Properties: Length prototype constructor
2 methods: CharAt (), charCodeAt (), concat (), fromCharCode (), IndexOf ()
LastIndexOf (), Match (), replace (), Serach (), slice (), substring (),
SUBSTR (), ValueOf (), toLowerCase (), toUpperCase (), Split ()
Date Day Object
Date objects are used to process dates and times
Get date of day
var date = new Date ();
document.write (date);
getFullYear (): Get year
Date.getfullyear ();
GetTime (): Get milliseconds
Date.gettime ();
setFullYear (): Set a specific date
Date.setfullyear ();
GetDay (): Get date
Date.getday ();
Get clock
1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Test</title>6 </Head>7 <Bodyonload= "StartTime ()">8 9 <Script>Ten functionStartTime () { One varToday= NewDate (); A varh=today.gethours (); - varm=today.getminutes (); - vars=today.getseconds (); the m=Checktime (m); - s=Checktime (s); - document.getElementById ("Timetxt"). InnerHTML=h+ ":" +m+":" +s; - varT=SetTimeout (function(){ + startTime (); - }, -); + } A functionChecktime (i) { at if(i<Ten){ - I="0"+i; - } - returni; - } - </Script> in <DivID= "Timetxt">Shenme</Div> - </Body> to </HTML>
Array Object
Use a separate variable name to store a series of values
Creation of arrays
var myArray = ["Hello", "Iwen", "IME");
Access to arrays
By setting the array name and index number, you can access a specific element
Note: [0] is the first element of the array. [1] is the second element of the array
Array Common methods:
Concat (): Merging arrays
Sort (): sort
Push (): Append element at end
Reverse (): array element rollover
<! DOCTYPE html>
Math Object
Perform common arithmetic tasks
Common methods
Round (): Rounding
Random (): Returns the number of 0~1 between
Max (): Returns the highest value
MIN (): Returns the lowest value in
ABS (): Return absolute value
There are other objects, browser objects, DOM objects, etc.
JavaScript built-in objects