JS/jQuery 遍历对象属性
生活随笔
收集整理的這篇文章主要介紹了
JS/jQuery 遍历对象属性
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Javascript For/In 循環(huán): 循環(huán)遍歷對象的屬性
var person={fname:"John",lname:"Doe",age:25};
for (x in person) {
txt=txt + person[x];
}
結(jié)果:JohnDoe25
jQueryjQuery.each() 遍歷對象屬性
var arr = ["one", "two", "three", "four", "five"]; var obj = { one: 1, two: 2, three: 3, four: 4, five: 5 }; 遍歷數(shù)組 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
相信才會最好
總結(jié)
以上是生活随笔為你收集整理的JS/jQuery 遍历对象属性的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 蜜雪冰城点40杯柠檬水多少钱?
- 下一篇: 一个女人一辈子租房过行吗?