Copy code code as follows:
<! Doctype HTML PUBLIC "-// W3C // DTD XHTML 1.0 Transitional // EN" http://www.w3.org/xhtml1/dtddml1-transitationAl.dtd ">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<Title> Re -sorting Method and Operation Method </Title>
<script type = "text/javascript">
// Sorting method
function basicsort () {
var values = [0,10,2,3,12,5];
Alert (valueS.reverse ()); // Reverse () method is just reversing the order of the array
Alert (values.sort ()); // sort () method compares the string, most of the cases are not the best solution
Alert (values.sort (compare)); // sort () method can receive a comparison function as a parameter
}
// Custom comparison functions, the returned array is a lifting order. It can also be changed by changing the code, such as Value1 <Value2 Return 1 and so on.
Function Compare (Value1, Value2) {
if (Value1 <Value2) {
Return -1;
} Else if (value1> value2) {{
Return 1;
} Else {
Return 0;
}
}
// Operation method Concat () method is to create a new array based on all items in the current array
Function BasicConcat () {
var colors = ["red", "blue", "pink"];
var colors2 = colors.concat ("yellow", ["black", "brown"]; // Red, Blue, Pink, YELLOW, BLACK, Brown, Brown
alert (colors2);
}
// The method is to create a new array based on all items in the current array, which can receive one or two parameters, that is, intercept End> Str> = Start
function basicsLice () {
var colors = ["red", "blue", "pink", "yello", "white"];
var colors2 = colors.slice (1);
var colors3 = colors.slice (1,4);
Alert (colors2);
Alert (colors3);
}
function basicsplice () {
var colors = ["red", "blue", "pink", "yello", "white"];
var remost = colors.splice (0,2); // Table delete the first two items
alert ("Deleted item:"+Removed+"---- The current item:"+colors)
Var Inserted = Colors.splice (1,0, "Black", "Gray"); // indicate 0 items at 1 place at the location, insert the new item into the new item, insert into the new item
Alert ("Now:"+colors);
}
</script>
</head>
<body>
<input type = "Button" value = "Sort" onClick = "Basicsort ();" />
<input type = "Button" value = "Concat" onClick = "BasicConcat ();" />
<input type = "Button" value = "SLice" onClick = "BasicsLice ();" />
<input type = "Button" value = "splice" onClick = "BasicSplice ();" />
</body>
</html>