var box=new Object();
box.name="张三";//创建属性以及初始化
box.age=23;
box.run=running();//创建方法
function running(){
return "我是中国人!";
}
document.write(typeof box+"<br/>");
document.write(box.name+"<br/>");
document.write(box.age+"<br/>");
document.write(box.run);
var box={
name:"张三",
age:23,
run:function(){
return "我是中国人!";
}
};
document.write(typeof box+"<br/>");
document.write(box.name+"<br/>");
document.write(box.age+"<br/>");
document.write(box.run());
function box(obj){
if(obj.name!=undefined)document.write(obj.name+"<br/>");
if(obj.age!=undefined)document.write(obj.age+"<br/>");
if(obj.love!=undefined)document.write(obj.love+"<br/>");
}
var obj={
name:"张三",
age:23
};
box(obj);
var box=new Array(1,2,3,4); document.write(typrof box+"<br/>");//Array属于Object类型 document.write(box);//输出1,2,3,4
var box=new Array(1,2,3,4); document.write(box[0]+box[1]+box[2]+box[3]);//输出1,2,3,4
var box=new Array(10);//创建数组默认必须是数字,必须是一位数字 box[3]=4;//初始化数组中的元素 box[5]=6; document.write(box);//输出,,,4,,6,,,,
var box=[1,2,3,4]; document.write(typrof box+"<br/>");//输出Object document.write(box.length+"<br/>");//输出数组的长度为4 document.write(box);//输出1,2,3,4
var box=[
{
name:"张三",
age:23
},//Object类型
[1,2,3,4],//Array类型
"JS",//String类型
25+25,//Number类型
new Array(1,2,3)//Array类型
];
document.write(typeof box+"<br/>");
document.write(box[0].name+"<br/>");
document.write(box[3]);
var box=[1,2,3,4]; document.write(box+"<br/>");//输出1,2,3,4 document.write(box.toString()+"<br/>");//输出1,2,3,4 document.write(box.valueOf()+"<br/>");//输出1,2,3,4 document.write(box.toLocaleString());//输出1,2,3,4
var box=[1,2,3,4];
document.write(box+"<br/>");
document.write(typeof box+"<br/>");
document.write(box.join("-")+"<br/>");
document.write(typeof box.join("-"));
var box=[1,2,3,4]; document.write(box+"<br/>"); box.push(5,6);//在数组末尾添加元素 document.write(box+"<br/>"); document.write(box.push(7,8)+"<br/>");//在数组末尾添加元素,并返回添加元素后数组的长度 document.write(box+"<br/>"); box.pop();//移除数组末尾的元素 document.write(box+"<br/>"); document.write(box.pop()+"<br/>");//移除数组末尾的元素,并返回移除的元素 document.write(box);
var box=[1,2,3,4]; document.write(box+"<br/>"); box.push(5,6);//在数组末尾添加元素 document.write(box+"<br/>"); document.write(box.push(7,8)+"<br/>");//在数组末尾添加元素,并返回添加元素后数组的长度 document.write(box+"<br/>"); box.shift();//移除数组前端的一个元素 document.write(box+"<br/>"); document.write(box.shift()+"<br/>");//移除数组前端的一个元素,并返回移除的元素 document.write(box);
var box=[1,2,3,4]; document.write(box+"<br/>"); box.unshift(0);//在数组的前端添加一个元素 document.write(box+"<br/>"); document.write(box.unshift(-1)+"<br/>");//在数组的前端添加一个元素,并返回添加元素会数组的长度 document.write(box+"<br/>"); box.pop();//在数组末尾移除元素 document.write(box+"<br/>"); document.write(box.pop()+"<br/>");//在数组末尾移除元素,并返回移除元素后数组的长度 document.write(box);
var box=[1,2,3,4,5]; box.reverse(); document.write(box+"<br/>");//输出54321 document.write(box.reverse());//再次进行逆序,输出12345
var box=[3,2,6,4,1,5]; box.sort(); document.write(box+"<br/>");//输出1,2,3,4,5,6 document.write(box.sort());//再次从小到大进行排序
var box=[0,15,10,1,5]; box.sort(); document.write(box);//输出0,1,10,15,5
function compare(value1,value2){
if(value1<value2){
return -1;
}
else if(value1>value2){
return 1;
}
else{
return 0;
}
}
var box=[0,15,10,1,5];
box.sort(compare);
document.write(box);//输出0,1,5,10,15
var box=[1,2,3,4,5]; var box1=box.concat(6);//创建新数组,并添加新元素 document.write(box1+"<br/>");//输出1,2,3,4,5,6, document.write(box);//原数组不变化
var box=[1,2,3,4,5]; var box1=box.slice(2);//取出索引为2以后的元素组成新的数组 document.write(box1+"<br/>");//输出3,4,5 document.write(box);//原数组不变化
var box=[1,2,3,4,5]; var box1=box.slice(2,3);//取出索引为2到3之间的元素组成新的数组 document.write(box1+"<br/>");//输出3 document.write(box);//原数组不变化
var box=[1,2,3,4,5]; var box1=box.splice(0,2);//截取索引为0开始的两个元素组成新的数组 document.write(box1+"<br/>");//返回截取的元素1,2 document.write(box);//当前数组被截取的元素被删除,输出3,4,5
var box=[1,2,3,4,5]; var box1=box.splice(4,0,6);//索引为4的位置插入了一个元素 document.write(box1+"<br/>");//返回新的数组为空,并没有截取元素 document.write(box);//当前数组索引为4的位置插入一个元素1,2,3,4,6,5
var box=[1,2,3,4,5]; var box1=box.splice(4,1,6);//索引为4的元素被替换,替换下来的元素组成新数组 document.write(box1+"<br/>");//返回新的数组5 document.write(box);//被替换后的原数组1,2,3,4,6
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有