首页 > Web开发 > 详细

JS/jQuery 遍历对象属性

时间:2016-11-07 12:18:17      阅读:213      评论:0      收藏:0      [点我收藏+]
Javascript For/In 循环: 循环遍历对象的属性
 
var person={fname:"John",lname:"Doe",age:25};  

 

for (x in person)  

 

  {  

   txt=txt + person[x];  

  }  

结果:JohnDoe25  

 

jQuery jQuery.each() 遍历对象属性

 var arr = ["one", "two", "three", "four", "five"];  

var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 };  

遍历数组

var text = "Array ";  

jQuery.each(arr, function(i, val) {  

    text = text + " #Index:" + i + ":" + val;  

});  

console.log(text);  

//Array  #Index:0:one #Index:1:two #Index:2:three #Index:3:four #Index:4:five  

遍历对象

text = "Object ";  

jQuery.each(obj, function(i, val) {  

    text = text + "Key:" + i + ", Value:" + val; 

});  

console.log(text);  

//Object Key:one, Value:1Key:two, Value:2Key:three, Value:3Key:four, Value:4Key:five, Value:5  

 
 

JS/jQuery 遍历对象属性

原文:http://www.cnblogs.com/kivenlv/p/6038076.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!