<script>
//----------------for用来遍历数组对象--
var i,myArr = [1,2,3];
for (var i = 0; i < myArr.length; i++) {
console.log(i+":"+myArr[i]);
};
//---------for-in 用来遍历非数组对象
var man ={hands:2,legs:2,heads:1};
//为所有的对象添加clone方法,即给内置原型(object,Array,function)增加原型属性,该方法很强大,也很危险
if(typeof Object.prototype.clone ==="undefined"){
Object.prototype.clone = function(){};
}
//
for(var i in man){
if (man.hasOwnProperty(i)) { //filter,只输出man的私有属性
console.log(i,":",man[i]);
};
}
//输出结果为print hands:2,legs:2,heads:1
for(var i in man) {//不使用过滤
console.log(i,":",man[i]);
}
//输出结果为
//hands : 2 index.html:20
//legs : 2 index.html:20
//heads : 1 index.html:20
//clone : function (){}
for(var i in man) {
if(Object.prototype.hasOwnProperty.call(man,i)) { //过滤
console.log(i,":",man[i]);
}
} //输出结果为print hands:2,legs:2,heads:1 </script>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有