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("数组赋值--------------------------");
arr[4] = "React.js";
writeDocument(arr);
arr[5] = "Vue.js";
writeDocument(arr);
arr[8] = "Angular.js";
writeDocument(arr);
writeDocument("获取数字长度--------------------------");
writeDocument("数组的长度是:" + arr.length);
writeDocument("获取数组某一段--------------------------");
writeDocument("数组1-2号元素是" + arr.slice(1, 3));
writeDocument("往数组头添加元素--------------------------");
writeDocument(arr.unshift("web", "Technology"));
writeDocument(arr);
writeDocument("往数组尾添加元素--------------------------");
writeDocument(arr.push("Bootstrap", "Sass"));
writeDocument(arr);
writeDocument("对字符串数组升序排序");
writeDocument(arr.sort());
var numArr = [3,6,9,1,4,11];
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);
function compare(a,b){
if(a>b){
return -1;
}
if(a==b){
return 0;
}
if(a<b){
return 1;
}
}
writeDocument("反转数组:" + numArr.reverse());
writeDocument("默认Join数组:" + numArr.join());
writeDocument("默认Join数组:" + numArr.join(":"));
writeDocument("默认Join数组:" + numArr.join("-"));
writeDocument("默认Join数组:" + numArr.join("><"));
console