1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Built-in objects</title>6 <Script>7 //5.Date8 //1) How to create a date9 varD1= NewDate ();Ten varD2= NewDate ("2017/09/01 09:09:09"); One Console.log (d1); A Console.log (D2); - //2) Convert to a local format string - Console.log (d1.tolocaledatestring ()); the Console.log (d1.tolocaletimestring ()); - //3) Read Time component - vary=d1.getfullyear (); - //month starts from 0 + varm=D1.getmonth ()+1; - varD=d1.getdate (); + varToday=y+ "years" +m+ "Month" +D+ "Day"; A Console.log (today); at - //6.RegExp - varStr= "You can up,no can no BB."; - //1) How to create a regular object - varReg= /No/; - //2) test () in //detects if the string contains a substring that matches a regular match - Console.log (Reg.test (str)); to //3) EXEC () + //Normal Mode - //detects a 1th substring that matches a regular match from a string the Console.log (reg.exec (str)); * Console.log (reg.exec (str)); $ //In the global modePanax Notoginseng //1th Call, the 1th substring matched to a regular match is detected from the string - //Nth call, the nth substring matched to the regular match is detected from the string the Reg= /No/G; + Console.log (reg.exec (str)); A Console.log (reg.exec (str)); the Console.log (reg.exec (str)); + Console.log (reg.exec (str)); - $ //7.Function $ functionsum () { - vars= 0; - if(arguments.length) { the for(varI=0; I<Arguments.length;i++) { - s+=Arguments[i];Wuyi } the } - returns; Wu } - About //Call function immediately when page loads $ console.log (SUM (1,2)); - console.log (SUM (3,4,5,6)); - - </Script> A </Head> + <Body> the - </Body> $ </HTML>
JS built-in objects