JS/jQuery 遍历对象属性
Posted Mr.Kiven
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS/jQuery 遍历对象属性相关的知识,希望对你有一定的参考价值。
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 遍历对象属性的主要内容,如果未能解决你的问题,请参考以下文章