function writeDocument(variable){
document.write(variable+"<br/>");
}
var arr = [3, 1, 2, 4, 5, 6];
writeDocument("获取数组的长度-------------------------");
document.write(arr.length + "<br/>");
writeDocument("获取数组的1-2号元素----------------------------");
document.write(arr.slice(1, 3) + "<br/>");
writeDocument("往数组头添加元素----------------------------");
arr.unshift(0);
document.write(arr+ "<br/>");
writeDocument("往数组尾部添加元素----------------------------");
arr.push(7);
document.write(arr+ "<br/>");
writeDocument("删除数组的第一个元素----------------------------");
arr.shift();
document.write(arr+ "<br/>");
writeDocument("删除数组的最后一个元素----------------------------");
arr.pop();
document.write(arr+ "<br/>");
writeDocument("对字符串进行升序的排序--------------");
writeDocument(arr.sort());
function downCompare(left,right){
if(left-right>0){
return -1;
}
if(left-right==0){
return 0;
}
if(left-right<0){
return 1;
}
}
function upCompare(left,right){
if(left-right>0){
return 1;
}
if(left-right==0){
return 0;
}
if(left-right<0){
return -1;
}
}
writeDocument("打印排序前的数字数组:"+ arr);
writeDocument("打印降序后的数字数组:"+ arr.sort(downCompare));
writeDocument("打印升序后的数字数组:"+ arr.sort(upCompare));
writeDocument("反转数组-------------");
writeDocument(arr.reverse());
writeDocument(arr.join(":"));
writeDocument(arr.join("<"));
writeDocument("给字符添加尖括号--------");
var strValue = "绿叶学习网";
var str = strValue.split("").join("><");
var arr1 = str.split("");
arr1.unshift("<");
arr1.push(">");
var result = arr1.join("");
document.write(result);
console