function writeDocument(variable) {
document.write(variable + "<br/>");
}
writeDocument("数组创建------------------------------------");
var arr=["HTML","CSS","JavaScript","jQuery","Vue.js" ];
writeDocument(arr);
writeDocument("数组小标取值------------------------------------");
writeDocument(arr[2]);
writeDocument("数组赋值------------------------------------");
arr[4]="React.js";
writeDocument(arr);
arr[5]="Vue.js";
writeDocument(arr);
arr[8]="Angular.js";
writeDocument(arr);
//2022/3/21
writeDocument("获取数组长度------------------------------------");
writeDocument("数组的长度为:" + arr.length);
writeDocument("获取数组的1-2号元素------------------------------------");
writeDocument(arr.slice(1,3));
writeDocument("往数组头添加元素----------------------------");
arr.unshift("xx");
writeDocument(arr);
writeDocument("往数组尾部添加元素----------------------------");
arr.push("yy");
writeDocument(arr + "<br/>");
writeDocument("删除数组的第一个元素----------------------------");
arr.shift();
writeDocument(arr + "<br/>");
writeDocument("删除数组的最后一个元素----------------------------");
arr.pop()
writeDocument(arr);
writeDocument("对字符串数组进行升序的排序----------------------------");
writeDocument(arr.sort());
var numArr=[3,4,11,12,9,10];
function upCompare(left,right){
if(left - right > 0){
return 1;
}
if(left - right == 0){
return 0;
}
if(left - right < 0){
return -1;
}
}
function downCompare(left,right){
if(left - right > 0){
return -1;
}
if(left - right == 0){
return 0;
}
if(left - right < 0){
return 1;
}
}
writeDocument("打印排序前的数字数组:" + numArr);
writeDocument("打印升序排列后的数字数组:" + numArr.sort(upCompare));
writeDocument("打印降序排列后的数字数组:" + numArr.sort(downCompare));
writeDocument("反转数组----------------------------");
writeDocument(numArr.reverse());
writeDocument(numArr.join(":"));
writeDocument(numArr.join("<"));
writeDocument("给字符添加尖括号----------------------------");
function addAngleBracket(strValue){
var a = strValue.split("").join("><");
var b = a.split("");//切开
b.unshift("<");
b.push(">");
return b.join("");//连接
}
var strValue = "绿叶学习网";
writeDocument(strValue);
writeDocument(addAngleBracket(strValue));
console