See the functions in JavaScript, objects

in JS

Method 1

Function function name () {

Functional body
}

详解JavaScript中的函数、对象

VAR function name = function () { function body

}



Method 3

详解JavaScript中的函数、对象
VAR function name = new function (“function body”);

Implementation

function name (); 详解JavaScript中的函数、对象

Object in JS

function is available in Java

Function TestDate () {var Date = new date (); // Document.Write (Date.Getdate () + ““); // // // //100 Document.write ( Date.getday () + “

“); // Return Month 0-11 Document.write (Date.getMonth () + “
“); // Returns 1900 to the current year Value 2018-1900Document.write (Date.GetyEAR () + “”); // Return to 2019Document.write (Date.GetfuLLYEAR () + “
"); // March 27, 2019 5:35:02: Return to the local time Document.write (Date.Tolocalestring () + "");} testdate 

2, mathematical object



function testMath () {// Get random number // random number The range is 0-1 var ran = math.random () * 1000; console.log (ran); // Take a down 756.9714434215177 == 756 console.log (Math.Floor (ran)); // Adjust 398.06376470341377 == 398 console.log (Math.ceil (ran)); // Get 4 bits of random number - verification code console.log (Math.Random () * 9000 + 1000);} TestMath
3, String Object

4, GLOBAL Object
   
5, three declaration methods of array objects

// mode A var arr = new array (); // mode 2 5 represents the length of the array Var arr2 = new array (5); // mode three var arr3 = new arch (“Hello”, 123, New String (), true); 详解JavaScript中的函数、对象

Array expansion

详解JavaScript中的函数、对象

   

详解JavaScript中的函数、对象 Function Demo4 () {var arr = [“BJSXT”, 123, New Date (), False]; // Array traversal mode a for (VAR i = 0; i

array common method: 详解JavaScript中的函数、对象

Push: Add one or more elements to the end of the array and return to a new array. POP: Delete the last element of the array

Shift: Delete the first element of the array
unshift: to an array At the beginning, add one or more elements and return to a new array. splice: Delete meaning starts to delete the number of subscripts
  <arr.length;i++){				
					console.log(arr[i]);
				}
				
				//数组遍历方式二 i :是代表数组的下标
				for(var i in arr ){		
					console.log(arr[i]);
				}		
			}
			demo4();
 
function Demo5 () {var arr = [“BJSXT”, 123, New Date (), false]; console.log (arr); // var le = arr.push (“we”); // var le = arr. POP (); // arr.shift (); // arr.unshift (“sxt”); // arr.splice (1, 2); // Added Meaning Added subscript 0: Delete the number of elements Added element arr.splice (1,0, “hello”); console.log (arr);} Demo5 ();

The above is a function of the small series to introduce the functions of JavaScript, and the object is explained. I hope to help everyone. If you have any questions, please leave a message, Xiaobu Reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!


© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment