Explore js special effects 06
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> js special effect </title>
<! -- <Link id = "link1" rel = "stylesheet" type = "text/css" href = "css1.css"/> -->
<Script>
Function AddNum (){
// Alert (arguments. length );
For (var I = 0; I <arguments. length; I ++ ){
Result + = arguments [I];
}
Alert (result );
}
AddNum (45,445,445,445, 4 );
</Script>
</Head>
<Body>
</Body>
</Html>
The following describes how to add and delete elements to an array: add (push) after an array, add (unshift) before an array, and delete (pop) after an array), delete (shift) before the array, as follows:
<Html xmlns = "<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> js special effect </title>
<! -- <Link id = "link1" rel = "stylesheet" type = "text/css" href = "css1.css"/> -->
Var arr = [1, 2, 3];
Alert ("original array content:" + arr );
Arr. push (4); // Add at the end
Alert ("add an element to the end of the array:" + arr );
Arr. unshift (0); // Add a header
Alert ("add an element to the array header:" + arr );
Arr. pop (); // tail deletion
Alert ("after deleting an element to the end:" + arr );
Arr. shift (); // Delete the header
Alert ("delete an element from the array header:" + arr );
</Script>
</Head>
<Body>
</Html>
Alternatively, We can insert, delete, and change data anywhere in the array. We can use splice as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> js special effect </title>
<! -- <Link id = "link1" rel = "stylesheet" type = "text/css" href = "css1.css"/> -->
Var arr = [1, 2, 4, 5, 6];
Alert ("prime group:" + arr );
// Delete: splice (starting point, length );
Arr. splice (2, 1 );
Alert ("after deletion 3:" + arr );
// Insert: splice (starting point, length, element ...);
Arr. splice (2, 0, 'A', 'B', 'C ');
Alert ("insert element:" + arr );
</Script>
</Head>
<Body>
</Body>
</Html>
Use join to split the array and add character join:
Var arr = [1, 2, 4, 5, 6];
Var a = arr. join ("--");
Alert ();
</Script>
Var arr = ["f", "z", "a", "e", "h", "m"];
Arr. sort ();
Alert (arr );
</Script>
<Script>
Var arr = [6,112, 38,454,];
Arr. sort (function (n1, n2 ){
Return n1-n2;
});
Alert (arr );
</Script>