Math&Date&Json
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-U-Compatible" content="IE-edge"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Math&Date&Json</title> </head> <body> <h1>Math</ H1 of > < Script type = "text / JavaScript" > var m = 3.1415926 ; // Math.ceil () rounding up, 'ceiling function' is applied to a multi-page page count console.log (Math.ceil ( m)); // . 4 // Math.floor rounding down, 'floor function' the console.log (Math.floor (m)); // . 3 // average of two numbers of maxima and minima var a = 18 is ; B = 25 ; the console.log (Math.max (A, B)); the console.log (Math.min (A, B)); // random number Math.random () in the range [0, 1) the console.log (Math.random ()); // randomly [100, 1000] integer the console.log (Math.ceil ( 100 + Math.random () * 900 )); // randomly (100,1000 ) integers the console.log (Math.floor ( 101 + Math.random () * 900 )); </ Script > < h1 of > a date </ h1 of > < Script type = "text / JavaScript" > // creation date objects var MyDate = new new a Date (); console.log (MyDate.toLocaleString ()); // Returns the morning local time 2019/7/1 11:18:33 console.log (MyDate.Date); // Returns the date and time according to local time console.log (MyDate .getFullYear ()); // returns the full-year according to local time console.log (MyDate.getMonth ()); // returns the month according to local time console.log (MyDate.getDate ()); // returns the specified time according to local date of the first day of the month of console.log (MyDate.getDay ()); // return 0 represents the day of the week according to local time Sunday console.log (MyDate.getHours ()); // returns the hour according to local time console .log (MyDate.getMinutes ()); // returns minutes according to the local time console.log (MyDate.getSeconds ()); // returns to local time according to </ Script > < h1 of > Json </ h1 of > < P > the JSON (the JavaScript Object Notation) is a lightweight data-interchange format, a fully language independent text format is ideal data exchange format. Meanwhile, JavaScript JSON is a native format, which means that processing JSON data in JavaScript does not require any special API or toolkit. </ P > < Script type = "text / JavaScript" > // transition between the object and the json json string var jsonStr = ' { "name": "xiaoxiao", "Age": "18 is", "weight" : "60Kg"} ' ; " : " Xiaohong " , " Age " : " 28 " , " weight " : " 70Kg " }; the console.log ( typeof jsonStr, typeof jsonObj); // string objects transfected json var newJsonObj = the JSON.parse (jsonStr) ; the console.log (newJsonObj, typeof newJsonObj); // JSON object-string var newJsonStr = the JSON.stringify (jsonObj); the console.log (newJsonStr,typeof newJsonStr); // 遍历 json对象 for(var k in jsonObj){ console.log(k + ' ' + jsonObj[k]) } // 遍历 json数组 var packAlex = [{"name":"xiaoxiao","age":"18","weight":"60Kg"}, {"name":"xiaohong","age":"28","weight":"70Kg"}]; for(var i in packAlex){//遍历packJson 数组时,i为索引 console.log(packAlex[i].name + " " + packAlex[i].weight); } </script> </body> </html>