Home  >  Article  >  Web Front-end  >  Two ways to traverse object arrays with jquery

Two ways to traverse object arrays with jquery

巴扎黑
巴扎黑Original
2016-11-25 14:11:571151browse

Two ways for jquery to traverse object arrays
data:
[
{
"templateId":5,"policyTemplateName":"fix",
"createTime":"2016-08-26 09:26:07"
}, an object
{
"templateId":6,"policyTemplateName":"Basic Template","createTime":"2016-08-26 01:46:28"
} Another object
]
returned to the background It is the object array in the above format. There are two situations for jquery traversal. One is to traverse the object and obtain it through the object.properties. The other is to traverse the object again to get the k(policyTemplateName) and k(policyTemplateName) of each object. value (basic template) value,
The use of the two cases is explained below
The first case:
function(data) {
Parameter i: represents the number of objects
Parameter obj: represents an object
$.each (data,function(i, obj) {
//Get the value of the corresponding field
console.log(obj.obj.templateId);
console.log(obj.obj.policyTemplateName);
});
}
th Two situations:
function(data) {
Parameter i: represents the object number
Parameter obj: represents an object
$.each(data, function(i, obj) {
//Traverse object obj again
Parameter k: represents the attribute name of the object
Parameter v: represents the attribute value of the object
$.each(obj,function(k,v){
if(k=="policyTemplateName"){
console.log(v);
}
});
});
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn