SOURCE

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

writeDoucument("数组创建-----------------------------------");
var arr = ["html","css","javascrip","wenty"];


writeDoucument(arr);

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

writeDoucument("数组赋值-------------------------------");
writeDoucument(arr);

arr[4] = "bb";
writeDoucument(arr);

arr[5] = "cat";
writeDoucument(arr);

arr[8] = "dog";
writeDoucument(arr);

writeDoucument("获取数组长度---------------------------");
arr1 = [1,2,3,4,5,6,7];
writeDoucument(arr.length);
writeDoucument(arr1.length);

writeDoucument("截取数组部分---------------------------");
writeDoucument(arr.slice(2,4));
writeDoucument(arr1.slice(2,4));

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

writeDoucument("往数组尾添加元素---------------------------");
writeDoucument(arr.push("bootstrap","sass"));
writeDoucument(arr);

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

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

writeDoucument("对字符串数组升序排序-----------------------");
writeDoucument(arr.sort());
writeDoucument(arr1.sort());

var numArr = [2,4,7,5,9,6,8,1];

writeDoucument(numArr);
function compare(a,b)
{
    if(a > b)
    {
        return 1;
    }
    if(a == b)
    {
        return 0;
    }
    if(a < b)
    {
        return -1;
    }
}
numArr.sort(compare);
writeDoucument("升序排列后:" + numArr);
function downcompare(a,b)
{
    if(a > b)
    {
        return -1;
    }
    if(a == b)
    {
        return 0;
    }
    if(a < b)
    {
        return 1;
    }
}
numArr.sort(downcompare);
writeDoucument("降序排列后:" + numArr);

writeDoucument("反转数组:" + numArr.reverse());
writeDoucument("默认Join数组:" + numArr.join());
writeDoucument("默认Join数组:" + numArr.join(":"));
writeDoucument("默认Join数组:" + numArr.join("-"));
writeDoucument("默认Join数组:" + numArr.join("><"));

//var string1 = "绿叶学习网";
//var arr2 = string1.split("").join("><");
//writeDoucument(arr2);
//writeDoucument(arr2.unshift("<"));
//writeDoucument(arr2.push(">"));
//writeDoucument(arr2);

var str1 = "绿叶学习网";
var str2 = str1.split("").join("><");
var arr3 = str2.split("");
arr3.unshift("<");
arr3.push(">");
var result = arr3.join("");
document.write(result);
console 命令行工具 X clear

                    
>
console