SOURCE

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

var arr = ["HTML","CSS","JavaScript","jQuery","Vue.js"]; 
writeDocument(arr[2]);
writeDocument(arr);

arr[4]="React.js";
writeDocument(arr[4]);
writeDocument(arr);

arr[5]="Vue.js";
writeDocument(arr[5]);
writeDocument(arr);
//赋值会不断添加到数组里面去,不会有越界一说。
arr[8]="Angular.js";
writeDocument(arr);

writeDocument("================================");
//获取长度
var arr1 = [];
var arr2 = [1, 2, 3, 4, 5, 6];
writeDocument(arr1.length);
writeDocument(arr2.length);
//获取数组某一段
var arr = ["HTML", "CSS", "JavaScript", "jQuery", "Vue.js"];
writeDocument(arr.slice(1, 3));
//数组头添加
 var arr = ["JavaScript", "jQuery"];
arr.unshift("HTML", "CSS");
writeDocument(arr);
//数组尾添加
var arr = ["HTML", "CSS"];
arr.push("JavaScript","jQuery");
writeDocument(arr);
//删除数组头
var arr = ["HTML", "CSS", "JavaScript", "jQuery"];
arr.shift();
writeDocument(arr);
//删除数组尾
var arr = ["HTML", "CSS", "JavaScript", "jQuery"];
arr.pop();
writeDocument(arr);

writeDocument("================================");
writeDocument(arr.sort());

var numArr=[8,6,9,7,4,11];
writeDocument("排序前:"+numArr);
function upcompare(a, b){
  if (a < b ){
    return -1;
}
  if (a > b ) {
    return 1;
}
  return 0;
}
numArr.sort(upcompare);
writeDocument("升序排序后:"+numArr);
function downcompare(a, b){
  if (a < b ){
    return 1;
}
  if (a > b ) {
    return -1;
}
  return 0;
}
numArr.sort(downcompare);
writeDocument("降序排序后:"+numArr);
numArr.reverse();
writeDocument("反向排列后的数组:" + numArr);
writeDocument("默认join数组:" + numArr.join());
writeDocument("默认join数组:" + numArr.join(":"));
writeDocument("默认join数组:" + numArr.join("><"));

writeDocument("================================");
function addAngleBracket(strValue){
    var strArr=strValue.split("");
    console.log(strArr);
    var str=strArr.join("><");
    console.log(str);
    strArr=str.split("");
    console.log(strArr);
    strArr.unshift("<");
    strArr.push("<");
    console.log(strArr);
    return strArr.join("");
}
writeDocument(addAngleBracket("绿叶学习网"));

writeDocument("================================");
function getSize(width, height, depth){
    var area = width * height;
    var volume = width * height * depth;
    var sizes = [area, volume];
    return sizes;
}
var arr = getSize(30, 40, 50);
writeDocument("底部面积为:" + arr[0]);
writeDocument("体积为:" + arr[1]);
console 命令行工具 X clear

                    
>
console