Traverse json data using jquery

后端 未结 2 936
轮回少年
轮回少年 2021-01-14 07:33

I have following json data

[
  {
    id: \"79\",
    title: \"Web+Infographics\",
    path: \"web-infographics\"
  },
  {
    id: \"80\",
    title: \"Miscel         


        
2条回答
  •  悲&欢浪女
    2021-01-14 07:50

    Quite simple, use jQuery.each:

    $.each(data, function (index, item) {
      console.log(item);
    });
    

    But, you don't really need jQuery for this simple task, give the native Array.prototype.forEach a try:

    data.forEach(function (item) {
      console.log(item);
    });
    

    If you have to support older browsers and don't want to depend on a library, a for-loop could to the trick:

    for (var i = 0; i < data.length; ++i) {
      var item = data[i];
    }
    

提交回复
热议问题