function writeDocument(variable) {
document.write(variable + "<br/>");
}
var arr = ["fnc","ass","skt","ssw","skt"];
writeDocument(arr[2])
writeDocument(arr)
arr[4]="roayl"
writeDocument(arr)
arr[5]="edg"
writeDocument(arr)
arr[8]="ig"
writeDocument(arr)
writeDocument("获取数组长度----------------------");
writeDocument("数组的长度为"+arr.length);
writeDocument("获取数组某一段----------------------");
writeDocument("数组的的某一段"+arr.slice(3,5));
writeDocument("往数组头添加元素----------------------");
arr.unshift("fpx", "dk");
writeDocument(arr);
writeDocument("往数组尾添加元素----------------------");
arr.push("fpx", "dk");
writeDocument(arr);
writeDocument("删除数组的第一个元素----------------------");
writeDocument("删除数组的元素"+arr.shift());
writeDocument(arr)
writeDocument("删除数组的最后一个元素-----------------------");
writeDocument("删除数组的元素"+arr.pop());
writeDocument(arr)
writeDocument("对字符串进行升序排列-----------------------");
writeDocument(arr.sort());
var numarr = [2,3196,23145,235,63791,2022,3014,5789];
writeDocument("排序前:"+numarr);
function upcompare(l,r)
{
if(l>r)
{
return 1;
}
if(l==r)
{
return 0;
}
if(l<r)
{
return -1;
}
}
numarr.sort(upcompare);
writeDocument("升序排序后"+numarr);
function downcompare(l,r)
{
if(l>r)
{
return -1;
}
if(l==r)
{
return 0;
}
if(l<r)
{
return 1;
}
}
numarr.sort(downcompare);
writeDocument("降序排序后"+numarr);
writeDocument("反转数姐:" + numarr. reverse());
writeDocument("默认join数组:" + numarr. join());
writeDocument("默认join数组:" + numarr. join(":"));
writeDocument("默认join数组:"+numarr. join("_"))
writeDocument("默认join数组:" + numarr. join("><"));
function addAngleBracket(strValue){
var strArr = strValue.split("");
console.log(strArr);
var str = strArr.join("><");
console.log(str);
strArr = str.split("");
console.log(strArr);
strArr.unshift("<");
strArr.push(">");
console.log(strArr);
return strArr.join("");
}
writeDocument(addAngleBracket("绿叶学习网"));
function JISUAN(x,y,z)
{
writeDocument("体积:" + x*y*z);
writeDocument("底面积:" + x*y);
}
JISUAN(2,4,5)
console