0513 Classroom 02 Arrays, mathematical functions, time functions

Source: Internet
Author: User
Tags mathematical functions

| built-in methods commonly used in arrays
|-push () and Pop ()
|--push () is added to the tail of the array, returning the length of the new array

var attr = [1,2,3,4,5];
var attr2 = [6,7,8,9,0];
var get = Attr.push (ATTR2);
Console.log (attr);
Console.log (get);


|--pop () is to delete the last item of the array, and to return the item that I deleted

var attr = [1,2,3,4,5];var get = Attr.pop (); Console.log (attr); Console.log (get);


|-unshift () and Shift ()
|--unshift () is added to the head of the array and returns the length of the new array

var attr = [1,2,3,4,5];var get = Attr.unshift (ten); Console.log (attr); Console.log (get);


|--shift () is to delete the first item of the array, and to return the item that I deleted

var attr = [1,2,3,4,5];var get = Attr.shift (); Console.log (attr); Console.log (get);


|-reverse () Reverses an item in an array

var attr = [1,2,3,4,5];
var get = Attr.reverse ();
Console.log (attr);
Console.log (get);

|-concat () Adds a new item at the end of the array

var attr1 = [1,2,3,4,5];
var attr2 = [6,7,8,9,0];
var get = Attr1.concat (ATTR2);
var get1 = Attr1.concat ("and", ATTR2);
var Get2 = Attr1.concat ("and" + attr2);
Console.log (get);
Console.log (GET1);
Console.log (Get2);


|-indexof () and LastIndexOf ()
|--indexof () returns the index of the first occurrence of the item found in the array, or 1 if not.

var = [4,1,66,4,23,2];var get = Attr.indexof (attr), var get = Attr.indexof (), Console.log (attr); Console.log (get);


|--laseindexof () returns the index of the first occurrence of the item found in the array, or 1 if not.

var = [4,1,66,4,23,2,66];var get = Attr.lastindexof (attr); var get = Attr.lastindexof (in); Console.log (attr); Console.log (get);


Math function Math
|-math.random random number between 0~1, 0 can be taken, 1 cannot be taken

Vvar attr = Math.random () var attr = parseint (Math.random () *100); Console.log (attr)


|-math.max, math.min maximum, minimum value

Math.max, math.min Maximum, minimum var attr = Math.max (1,6,8,2), var attr = Math.min (1,6,8,2); Console.log (attr);


|-math.pi Pi

var attr = Math.pi;console.log (attr);


| time function
|-var mydate = new Date ();

Press CTRL + C to copy the code<textarea></textarea>Press CTRL + C to copy the code

0513 Classroom 02 Arrays, mathematical functions, time functions

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.