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

JS simple method of looping through json array_javascript skills

WBOY
Release: 2016-05-16 15:04:27
Original
3428 people have browsed it

The example in this article describes how to simply loop through a json array using JS. Share it with everyone for your reference, the details are as follows:

For example, the json string in the database is like this

var str = '[{"name":"宗2瓜","num":"1","price":"122"},{"name":"宗呱呱","num":"1","price":"100"}]';
var xqo = eval('(' + str + ')');
for(var i in xqo){
  alert(xqo[i].name);
}

Copy after login

The above is js, the following is jquery to parse json string,

var cc = jQuery.parseJSON(data);
alert(cc[0].title);

Copy after login

For looping, it’s the same as above

For more JavaScript-related content, please check out the special topics on this site: "Summary of json operation skills in JavaScript", "Summary of JavaScript switching special effects and skills", "JavaScript Summary of Search Algorithm Techniques", "Summary of JavaScript Animation Special Effects and Techniques", "Summary of JavaScript Errors and Debugging Techniques", "Summary of JavaScript Data Structure and Algorithm Techniques ", "Summary of JavaScript traversal algorithms and techniques" and "Summary of JavaScript mathematical operation usage"

I hope this article will be helpful to everyone in JavaScript programming.

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