Is it possible to create an empty multidimensional array in javascript/jquery?

后端 未结 8 2218
粉色の甜心
粉色の甜心 2020-12-06 10:36

I am trying to create a very basic Flickr gallery using the Flickr API. What I want to achieve is sorting my pictures by tag. What I am using is jQuery.getJSON() so that I c

8条回答
  •  佛祖请我去吃肉
    2020-12-06 11:41

    I think something like this should do what you want

     var imageArray = [];   
    
     $.each(data.photoset.photo, function(i, item) {
    
       // if the tag is new, then create an array
       if(!imageArray[item.tags])
         imageArray[item.tags] = [];
    
       // push the item url onto the tag
       imageArray[item.tags].push(item.url_sq);
    
     });
    

提交回复
热议问题