Array数组
一些属性
.push()//方法 往数组最后一位添加成员!
.unshift() // 往数组第一位添加成员!
.pop() // 将数组最后一位成员弹出!
.shift () // 将数组第一位成员弹出!
.join() // 将数组转换成字符串!
.split()// 将字符串重新生成数组!括号里面写分隔符(自定义的);看字符串
.reverse() // 将数组成员倒序排列
.concat ()//将两个数组进行合并!
.splice(1,2,3,4)//将数组中从下标为1的成员开始删除两个值 并在删除的位置添加3和4
一些实例
提取:http://www.taobao.com?username=zhangshan&password=123456 该网址里面的username和password部分。
<script>
var url1="http://www.taobao.com?username=zhangshan&password=123456";
var skr = url1.split("?");
var sk2=skr[1];
var kkk=sk2.split("&");
var t1=kkk[0];
var t2=kkk[1];
var user=t1.split("=");
var pass=t2.split("=");
document.write(user[1]);
document.write("<br />")
document.write(pass[1]);
</script>
数组去重复!
<script>
var arr = ["a","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b","b","a","c","d","f","b"];
var sum = [];
var flag = true;
for (var i in arr) {
flag = true;
for (var j in sum) {
if (arr[i] == sum[j]) {
flag = false;
}
} if (flag) {
sum.push(arr[i]);
}
}
document.write(sum);
</script>
var math=["语文=99","数学=90","英语=88","历史=25","化学=30","生物=80","体育=99","物理=100","政治=70"];求最大最小平均分总分!
<script>
var math=["语文=99","数学=90","英语=88","历史=25","化学=30","生物=80","体育=99","物理=100","政治=70"];
var fenshu1 = [];
var fenshu2 = [];
for (var index in math) {
var fenshu1 = math[index].split("=");
fenshu2.push(parseInt(fenshu1[1]));
}
fenshu2.sort(daxiao);
var sum = 0;
for (var index in fenshu2) {
sum += fenshu2[index];
}
document.write("最低分为:" + fenshu2[0] + "<br />" + "最高分为:" + fenshu2[8] + "<br />" + "平均分为:" + sum / 9 + "<br />" + "总分为:" + sum)
//函数大小定义
function daxiao(a, b) {
if (a > b) {
return 1;
} else if (a == b) {
return 0;
} else if (a < b) {
return -1;
}
}
</script>