JS Learning 2

Source: Internet
Author: User

function return value

function sum (A, B)
Return a+b
Can have return, no return, if no return returned undefined
return; also undefinded
A function should return only one type of value

Variable parameter
Arguments array--all parameters

Function Show ()


alert (arguments.length);
Gets the array of the arrays
var sum = 0;
for (Var i=0;i<arguments.lenght;i++)

Sum +=arguments[i]

Show (+)

For any number of and

CSS functions
function css ()
if (arguments.length = = 2)
return arguments[0].style.arguments[1];
}else if (arguments.length = = 3)
ARGUMENTS[0].STYLE.ARGUMENTS[1] = arguments[2]
Style can only get styles between lines how to get a non-inline style
Currentstyel gets the calculated style can only be used under the ID
Firefox with getComputedStyle (Odiv,false) The second parameter is not used


Package GetStyle (OBJ,STTR)
if (Obj.currentstyle)
return obj.currentstyle[attr]
Return getComputedStyle (Obj,false) [attr]
Get background is a composite style, which is undefined

define var arr = [+/-]
var arr = new Array ()
Properties of the array
Can be set or get can be used to empty the array
Arr.length = 0
Push to add an element to the array
Push (3)
Shift to remove elements from the head of an array
Unshift adding elements to the head of an array

Sorting of arrays
Sort () sorts an array
var arr = [' Z ', ' A ', ' C ', ' B '];
Sort (arr)

var arr = [3,2,4,1]
Sort number out problem
Need to give a comparison function sort (function (n1,n2) {return n1-n2})

Concat () Connect two arrays

ARR3 = Arr1.concat (ARR2)
Join () splits an array
Arr.join (', ')
String Conversions to arrays
var str = ' All-in-all ';
var arr = str.split (', ')

Splice (start, length, Element)
Remove some elements from the middle of an array
Insert some elements
Arr.splice (4,0, ' A ', ' B ') Delete 0, insert some elements
Arr.splice (, ' A ', ' B ')

Delete the element first, then insert the element

JS Learning 2

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.