JavaScript built-in objects

Source: Internet
Author: User

JS function Features
Only the call is executed, the parameter cannot be specified with Var, the function is called according to the nearest principle, the function returned in the method body is called, and the returned result is directly assigned to the OnClick button as the value of the OnClick property, which needs to be displayed on the page using alert ().

JS Container
The array is the only container in JS , which can be numbered, the elements can be any type, not the same type, and the array in JS can pass over some indexes to the value.

var arr = [1,2,3,4,5,6]; // using {} in Java var New Array ();
arr[0]= "haha";
arr[1]= "haha";
arr[2]= "haha";
arr[4]= "haha"; a
Lert (arr.length); // 5
Alert (arr[3]);//undifinedvarnew Array (3); // even if the array is given a length of 3, but can also be out of range assignment
arr[3]=4;
alert (arr.length);//4new Array (1,2,3,4);
Arr[2]= "Hello"; // 3 replaced with "Hello"
Arr[4]= "World";//Add a new element

JS built-in objects

Array object, Math object, string object, Date Date object, Global object.

vararr =NewArray ();
varDate =NewDate ();
varnum = math.abs (-100);
alert (num);//100alert (Math.PI);//3.141592653589793varArr=[1,2,3,4,5];alert (Arr.join ("-"));//1-2-3-4-5
Alert (Arr.reverse ());//[5,4,3,2,1]JS Get current date
var time =NewDate ();
varYear = Time.getfullyear ();//2015
var month = Time.getmonth () +1;//default starting from 0
var day = Time.getdate ();//getday () returns one of the days of the week (0-6)
var hour = time.gethours ();
var minute = Time.getminutes ();
minute = Minute>9?minute: "0" +minute;
var second = Time.getseconds ();
Second = Second>9?second: "0" +second;
var str = "+year+month+day+hour+minute+second;//not added" will perform a numeric operation
alert (str);//20151015173542JS gets the specified date
varnow =NewDate ();//Get a date 7 days ago
var start_milliseconds = Now.gettime () -1000*60*60*24*7;
var start = new Date ();
Start.settime (Start_milliseconds);
var startyear = Start.getfullyear ();
var startmonth = Start.getmonth () +1;
Startmonth = Startmonth>9?startmonth: "0" +startmonth;
var startday = Start.getdate ();
StartDay = Startday>9?startday: "0" +startday;
var startTime = startyear+ "-" +startmonth+ "-" +startday;
$ ("#task_start_time"). Val (startTime);

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.