JavaScript built-in objects

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.