JavaScript Basics (Ii.)

Source: Internet
Author: User
Tags pow time and date

    • Object

JavaScript is an object-oriented language, so you can use object-oriented thinking to design a JavaScript object is a data entity that is composed of some properties and methods that are related to each other.

    • JS built-in objects

As a programming language, JavaScript provides a number of built-in objects and functions. Built-in objects provide several of the most common features of programming. There are several types of JavaScript built-in objects.
String object: Handles all string operations
Math object: Handling all mathematical operations
Date object: Handling the storage, conversion, and expression of dates and times
Array object: Provides a model of an array, storing large amounts of ordered data
Event object: Provides various processing information for JavaScript events
Built-in objects have their own methods and properties and are accessed in the following ways:
Object name. Property name
Object name. Method name (parameter table)

Time Object

A time object is a built-in object of JavaScript that must be declared before it can be used.
Basic syntax

1 var date=New

Note the use of the keyword new here, the first letter of Data () must be capitalized.
Grammatical explanations
Use new to declare a new object entity. The syntax for using the new operator is as follows:
Instance object name =new object name (parameter list)
The Date object provides the following 3 classes of methods:
Get the current time and date from the system
Set the current date and time
Complete the conversion between time and date with a string

1 varMyDate =NewDate ();2Mydate.getfullyear ();//Get the full year (4-bit, 1970-????)3Mydate.getmonth ();//Get the current month (0-11, 0 for January)4Mydate.getdate ();//get current day (1-31)5Mydate.getday ();//get Current week x (0-6, 0 for Sunday)6Mydate.gettime ();//Gets the current time (the number of milliseconds since 1970.1.1)7Mydate.gethours ();//gets the current number of hours (0-23)8Mydate.getminutes ();//gets the current number of minutes (0-59)9Mydate.getseconds ();//gets the current number of seconds (0-59)TenMydate.getmilliseconds ();//gets the current number of milliseconds (0-999) OneMydate.tolocaledatestring ();//Get Current date AMydate.tolocaletimestring ();//Get current Time -Mydate.tolocalestring ();//get date and time

Math Object

The Math object is used to handle complex mathematical operations. The Math object is a global object of JavaScript and does not need to be created with new.

Math.Abs ( -2);           // the method can return the absolute value of a number. Math.Round (5.5);     // This method rounds a number to the nearest integer. math.random ();      // the method can return a random number between 0 (inclusive) ~ 1 (not included). Math.ceil (1.4);        // the Ceil ()   method returns the smallest integer greater than or equal to X. (Take large whole)Math.floor (1.6);       // the Floor () method returns the largest integer less than or equal to X. (Take small whole)Math.pow (4,3);       // the POW () method returns the Y power of X.  (4 of the 3-second party)    

Array Object


Basically all programming languages provide array objects, which organize the same kind of data together, which is very convenient and efficient to access. such as the Java and C languages. As with the C language, the subscript of an array begins with a clump of zeros. Once an array is created, you can use the [] symbol to access an array of individual elements.

3 ways to define an array

var New  varnew Array (' Monday ', ' Tuesday ', ' Wednesday 'var week = [' Monday ', ' Tuesday ', ' Wednesday ');

Property:
constructor function reference for objects created by
Prototype properties and methods that can be added to an object
Index for an array created by a regular expression match, the zero-based index of the match in the string.
Input for an array created by a regular expression match, reflects the original string against which the regular Expressio N was matched.
Length gets the number of array elements, that is, the maximum subscript plus 1
Method (13):
Concat (Array1,arrayn) joins two or more than two array values and returns the result after merging
Join (String) merges elements of the array into strings, string as delimiters. If omitted, it is merged directly, no longer separated
Pop () moves the last element in the array and returns the element
Push (value) adds one or more elements to the end of the array and returns a new array length value
Reverse () Reverses the order of the elements in the array, and reverses the arrangement
Shift () moves the first element in an array and returns the element
Slice (start, deletecount, [item1[, item2[,... [, Itemn]]]) Removes one or more elements from an array and, if necessary, inserts a new element at the location of the removed element, returning the element that was removed
Sort (compare Function), in the case of no sort number, is arranged alphabetically by element, and if it is not a string type, it is converted to a string and then sorted, returning the sorted array
Splice () to delete and add new elements to an array
Tosource () Displays the source code of the object
ToString () returns a string of all elements of the array, separated by commas
Unshift (value) adds one or more elements to the beginning of an array, and returns the new length
ValueOf () returns the original value of the array object

JavaScript Basics (Ii.)

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.