Home >Web Front-end >JS Tutorial >JS simple method of looping through json array_javascript skills

JS simple method of looping through json array_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:04:273439browse

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);
}

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

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

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.

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