Basic JavaScript Usage--blog Park Old Bull Lecture Hall

Source: Internet
Author: User

I recently summed up the use of javascript, the following share to you-focus on the blog Park Old Bull lecture hall

Use of Arrays:

var arr=[10,1,66,55,100,5,2,7,1];

var arr1=[4,8,11];

Console.log (arr.push (4,8,11));//add The end element, return the length of the array

Console.log ("add element at the end:" +arr);

Console.log (arr.unshift (4,8,11));//add Header element, return array length

Console.log ("add element at the beginning:" +arr);

Console.log (arr.shift ());//delete The first element of the array, return the deleted element if the array is not empty, and return the undefined

Console.log ("delete the first element:" +arr);

Console.log (arr.pop ());//delete The last element of the array, return the deleted element if the array is not empty, and return the undefined

Console.log ("delete last element:" +arr);

Console.log (a=arr.concat (arr1));//connection Array

Console.log ("connected array" +a);

var arr=[10,1,66,55,100,5,2,7,1];

Console.log ("middle plus-after result" +arr.join ("-"));//the middle of each element plus-

Console.log ("sort:" +arr.sort ());//not A full sort, parentheses can be added value

Console.log (arr.splice (2,2, "1", "1"));//the first element represents the starting position, the second element represents the number of substituted elements, and the next two represent the substituted elements.

Console.log ("array to string" +arr.join ());

Application of Strings:?--pay attention to blog Park Lao Niu da Lecture Hall

?

var str= "Hello world";

var str1=["Lao", "Niu"];

Console.log ("returns The first subscript of the element" +str.indexof ("l"));

Console.log ("first parameter, intercept start position, second intercept length" +str.substr);

Console.log ("first parameter, intercept start position, second end position" +str.substring);

Console.log ("return character based on position" +str.charat (3));

Console.log ("the element is intercepted in the array returned to" +str.split ("l"));

Console.log ("intercept string" +str.slice ());

Console.log ("becomes lowercase" +str.tolowercase ());

Console.log ("becomes uppercase" +str.touppercase ());

Basic JavaScript Usage--blog Park Old Bull Lecture Hall

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.