SOURCE

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

var arr = ["HTML","CSS","JavaScript","jQuery","Vue.js"];

writeDocument(arr[2]);

writeDocument(arr);

writeDocument("数组赋值------------------------------------------------------- <br/>");
arr[4] = "React.js";

writeDocument(arr);

arr[5] = "Vue.js";

writeDocument(arr);

arr[8] = "ANgular.js";

writeDocument(arr);

writeDocument("获取数组长度-----------------------------------------------------<br/>");
writeDocument("数组长度为:" + arr.length + "<br/>");

writeDocument("获取数组某一段---------------------------------------------------<br/>");
writeDocument("数组1-2号元素为:" + arr.slice(1 , 3) + "<br/>");

writeDocument("往数组头部添加元素------------------------------------------------<br/>");
writeDocument(arr.unshift("Web","Technology") + "<br/>");
writeDocument(arr + "<br/>");

writeDocument("往数组尾部添加元素------------------------------------------------<br/>");
writeDocument(arr.push("Bootstrap","Sass") + "<br/>");
writeDocument(arr + "<br/>");

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

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

writeDocument("对字符串数组按升序排序---------------------------------------------<br/>");
writeDocument(arr.sort() + "<br/>");

var numArr = [3, 6, 9, 11, 13, 15];

writeDocument("排序前:" + numArr);
function upcompare(l , r){
    if (l > r){
        return 1;
    }
    if (l == r){
        return 0;
    }
    if (l < r){
        return -1;
    }
}
numArr.sort(upcompare);
writeDocument("升序排序后:" + numArr);

function downcompare(l , r){
    if (l > r){
        return -1;
    }
    if (l == r){
        return 0;
    }
    if (l < r){
        return 1;
    }
}
numArr.sort(downcompare);
writeDocument("降序排序后:" + numArr);




console 命令行工具 X clear

                    
>
console