Home > Web Front-end > JS Tutorial > body text

jQuery traversal json method list

伊谢尔伦
Release: 2016-11-24 15:24:48
Original
1377 people have browsed it

1. for loop:

var obj = { 
    "status":1, 
    "bkmsg":"\u6210\u529f", 
    "bkdata":["\u5415\u5c1a\u5fd7","1387580400","\u6dfb\u52a0\u8bb0\u5f55"] 
} 
// console.log(obj.length); 
if (obj.status == 1) { 
    for (var i = 0; i < obj.bkdata.length; i++) { 
        console.log(obj.bkdata[i]); 
    }; 
}else{ 
    alert("数据有误~"); 
};
Copy after login

2. for in loop:

//for in循环 
for(x in obj.bkdata){ 
    //x表示是下标,来指定变量,指定的变量可以是数组元素,也可以是对象的属性。 
    console.log(obj.bkdata[x]); 
}
Copy after login

3. each method

if (obj.status == 1) { 
     $(obj.bkdata).each(function(index,item){ 
         //index指下标 
         //item指代对应元素内容 
         //this指代每一个元素对象 
         //console.log(obj.bkdata[index]); 
         console.log(item); 
         //console.log($(this)); 
    }); 
}else{ 
    alert("数据有误~"); 
};
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template