Home > Article > Web Front-end > How to loop through JSON data in JS
This article mainly introduces the method of JS looping through JSON data. It has a certain reference value. Now I share it with you. Friends in need can refer to it.
JSON data such as: {"options" :"[{/"text/":/"Wangjiawan/",/"value/":/"9/"},{/"text/":/"Lijiawan/",/"valu
e/":/"10/"},{/"text/":/"Shaojiawan/",/"value/":/"13/"}]"}
Use js It can be written as:
var data=[{name:"a",age:12},{name:"b",age:11},{name:"c",age:13},{name:"d",age:14}]; for(var o in data){ alert(o); alert(data[o]); alert("text:"+data[o].name+" value:"+data[o].age ); }
or
<script type="text/javascript"> function text(){ var json = {"options":"[{/"text/":/"王家湾/",/"value/":/"9/"},{/"text/":/"李家湾/",/"value/":/"10/"},{/"text/":/"邵家湾/",/"value/":/"13/"}]"} json = eval(json.options) for(var i=0; i<json.length; i++) { alert(json[i].text+" " + json[i].value) } } </script>
Related recommendations:
JS loop Nodelist Dom list 4 Way
The above is the detailed content of How to loop through JSON data in JS. For more information, please follow other related articles on the PHP Chinese website!