JavaScript---basic syntax

Source: Internet
Author: User

String method:
Str.length
Str.charat (i): takes one of the strings;
Str.indexof (' e '); Find the first place to appear; return-1 is not found;
Str.lastindexof (' e '): Find the last position where e appears; return-1 is not found;
Str.touppercase (); turn caps
Str.tolowercase (); Turn lowercase
Str.substring (starting position, end position): string interception;
Str.split (' Cut Way '); string cut; string-to-array;

Array method:

Delete: Arr.splice (start position, number of deletions);
Added: Arr.splice (the beginning of the position [to which the front of the add],0, element 1);
Replacement: Arr.splice (start position, number of deletions, element 1);
Arr.sort (function (n1,n2) {return n1-n2}): Sort
Arr.reverse (): Flip
Arr.push (); Add a bit to the back of the array;
Arr.unshift (): Adds a bit to the front of the array;
Arr.pop (): Deletes a bit from the back of the array;
Arr.shift (): Deletes a bit from the front of the array;
Arr.join (' Connected way '); array-to-string method;
Arr.concat (arr1,arr2); array connections;


6. Mathematical Methods:
Math.random (); random number;
Math.Round (): rounded;
Math.ceil () upward rounding;
Math.floor () downward rounding;
Math.Abs (): Take absolute value;
Math.max (x, y): Maximum number;
Math.min (x, y), minimum number;
Math.pow (x, y): several times;
MATH.SQRT (): Open square;

Array: Store multiple things;
JSON: Save multiple things;
JSON = {
Key-value pairs
name1[keys, key]:value1[values, value],
name2[keys, key]:value2[values, value],
}

The difference between JSON and arr:

1:lengthundefinedarr.length;
2: The way of subscript attribute arr[0];
3: The order has no order in order;
4: Loop for infor,while,for in

The For In loop can also loop an array, but it is not recommended because the performance is slightly lower;

JS Small Features:
Comma expression: see only the value after the last comma;

JavaScript---basic syntax

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.