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);
arr[5]="Vue.js";
writeDocument(arr);
arr[8]="Angular.js";
writeDocument(arr);
writeDocument("获取数组长度------------------");
document.write(arr.length+"<br/>");
writeDocument("获取数组某一段------------------");
document.write(arr.slice(1,4)+"<br/>");
writeDocument("往数组头添加元素------------------");
arr.unshift("aaa","bbb")
document.write(arr+"<br/>");
writeDocument("往数组尾添加元素------------------");
arr.push("ccc","ddd");
document.write(arr+"<br/>");
writeDocument("删除数组第一个元素------------------");
arr.shift();
document.write(arr+"<br/>");
writeDocument("删除数组最后一个元素------------------");
arr.pop();
document.write(arr+"<br/>");
writeDocument("对字符串数组按升序排序------------------");
writeDocument(arr.sort());
var numArr=[3,6,9,1,4,11];
writeDocument("排序前: "+numArr);
function upcompare(a,b){
if(a>b){
return 1;
}
if(a==b){
return 0;
}
if(a<b){
return -1;
}
}
numArr.sort(upcompare);
writeDocument("升序排序后: "+numArr);
function compare(a,b){
if(a>b){
return -1;
}
if(a==b){
return 0;
}
if(a<b){
return 1;
}
}
numArr.sort(compare);
writeDocument("降序排序后: "+numArr);
writeDocument("反转数组: "+numArr.reverse());
writeDocument("默认join数组:"+numArr.join());
writeDocument("join数组: "+numArr.join(":"));
writeDocument("join数组: "+numArr.join("-"));
writeDocument("join数组: "+numArr.join("><"));
var a = "绿叶学习网";
var b = a.split("").join("><");
var arr1 = b.split("");
arr1.unshift("<");
arr1.push(">");
var result = arr1.join("");
document.write(result);
console