SOURCE

function writeDocument(variable)
{
    document.write(variable + "<br/>");
} 

//writeDocument(arr);

writeDocument("数组创建-------------------")
var arr = ["HTML","CSS","JavaScript","jQuery","Vue.js"];
writeDocument(arr);

writeDocument("数组下标取值-------------------")
writeDocument(arr[2]);

writeDocument("数组赋值-------------------")
arr[4]="React.js";
writeDocument(arr);
arr[5]="Vue.js";
writeDocument(arr);
arr[8]="Angular.js";
writeDocument(arr);

writeDocument("获取数组的长度-------------------");
writeDocument("数组的长度是:" + arr.length);

writeDocument("获取数组的1-2号元素-------------------");
writeDocument(arr.slice(1,3));

writeDocument("往数组头添加元素-------------------");
writeDocument(arr.unshift("web","move"));
writeDocument(arr);

writeDocument("往数组尾添加元素-------------------");
writeDocument(arr.push("hero","loser"));
writeDocument(arr);

writeDocument("删除数组的第一个元素------------------");
writeDocument("删除元素:" + arr.shift());
writeDocument(arr);

writeDocument("删除数组的最后一个元素-------------------");
writeDocument("删除元素:" + arr.pop());
writeDocument(arr);

writeDocument("对字符串数组进行升序的排列--------------");
writeDocument(arr.sort());

var numArr = [3,4,11,12,9,10];

function upCompare(left,right){
    if(left - right > 0){
        return 1;
    }
    if(left - right == 0){
        return 0;
    }
    if(left - right < 0){
        return -1;
    }
}

function downCompare(left,right){
    if(left - right > 0){
        return -1;
    }
    if(left - right == 0){
        return 0;
    }
    if(left - right < 0){
        return 1;
    }
}

writeDocument("打印排序前的数组:" + numArr);
writeDocument("打印升序后的数组:" + numArr.sort(upCompare));
writeDocument("打印降序后的数组:" + numArr.sort(downCompare));

writeDocument("反转数组-------------------");
writeDocument(numArr.reverse());
writeDocument(numArr.join(":"));
writeDocument(numArr.join("<"));

writeDocument("给字符添加尖括号-------------------");
function addAngleBracket(strValue){
    var str1 = strValue.split("");
    var str2 = str1.join("><");
    str1=str2.split("");
    str1.unshift("<");
    str1.push(">");
    return str1.join("");
}
var strValue = "绿叶学习网";
writeDocument(strValue);
writeDocument(addAngleBracket(strValue));
console 命令行工具 X clear

                    
>
console