function writeDocument(variable){
document.write(variable + "<br/>");
}
document.write("数组创建----------------------------------" + "<br/>")
var arr=["HTML","CSS","JavaScript","jQuery","Vue.js"];
document.write(arr + "<br/>");
document.write("数组下标取值----------------------------------" + "<br/>")
document.write(arr[2] + "<br/>");
document.write(arr + "<br/>");
arr[4]="React.js";
document.write(arr + "<br/>");
arr[5]="Vue.js";
document.write(arr + "<br/>");
arr[8]="Angular.js";
document.write(arr + "<br/>");
document.write("获取数组长度----------------------------------" + "<br/>")
var arr1=[];
var arr2=[1,2,3,4,5,6];
document.write(arr1.length + "<br/>");
document.write(arr2.length + "<br/>");
document.write("获取数组某一段----------------------------------" + "<br/>")
document.write(arr.slice(1,3) + "<br/>");
document.write("往数组头添加元素----------------------------------" + "<br/>")
var arr3=["JavaScript","jQuery"];
arr3.unshift("Html","css");
document.write(arr3 + "<br/>");
document.write("往数组尾添加元素----------------------------------" + "<br/>")
arr3.push("Html","css");
document.write(arr3 + "<br/>");
document.write("删除数组的第一个元素----------------------------------" + "<br/>")
var arr4=["Html","css","JavaScript","jQuery"];
arr4.shift();
document.write(arr4 + "<br/>");
document.write("删除数组的最后一个元素----------------------------------" + "<br/>")
arr4.pop();
document.write(arr4 + "<br/>");
document.write("对字母字符串数组按升序排序----------------------------------" + "<br/>")
document.write(arr.sort() + "<br/>");
var numArr = [3,6,9,1,4,11];
document.write("排序前:" + numArr + "<br/>");
function upcompare(l,r){
if(l>r){
return 1;
}
if(l==r){
return 0;
}
if(l<r){
return -1;
}
}
numArr.sort(upcompare);
document.write("升序排序后:" + numArr + "<br/>");
function downcompare(l,r){
if(l>r){
return -1;
}
if(l==r){
return 0;
}
if(l<r){
return 1;
}
}
numArr.sort(downcompare);
document.write("降序排序后:" + numArr + "<br/>");
document.write("反转数组:" +numArr.reverse() + "<br/>");
document.write("默认Join数组:" +numArr.join() + "<br/>");
document.write("默认Join数组:" +numArr.join(":") + "<br/>");
document.write("默认Join数组:" +numArr.join("-") + "<br/>");
document.write("默认Join数组:" +numArr.join("><") + "<br/>");
var str1="绿叶学习网";
var str2=str1.split("").join("><");
var arr = str2.split("");
arr.unshift("<");
arr.push(">");
var result=arr.join("");
document.write(result);
console