1

I am a beginner programmer trying to combine two arrays I got two two different functions, ebay(); and etsy();and displaying the results in a table.

1.etsy() gets its array from jQuery:

var b;
(function($){
    $(document).ready(function(){
        $('#etsy-search').bind('submit', function() {
        //Making API call to Etsy to retrieve product arrays
        //...
        //Making an ajax call 
            $.ajax({
                url: etsyURL,
                dataType: 'jsonp',
                success: function(data) {
                    if (data.ok) {
                    //assigned variable b to the data.results
                    //alert(b) returns: [object Object],[object Object]
                        b = (data.results);     
                    //start next function
                        ebay(b);

                    }}});return false;})});})(jQuery);

2.ebay() retrieves the array from Javascript and displays both the array

    ebay(b){
    //Making API call to Ebay to retrieve product arrays
    //...
                            //function to retrieve ebay arrays
                            function _cb_findItemsByKeywords(root) {
                                //assigns var items the result array
var items = root.findItemsByKeywordsResponse[0].searchResult[0].item || [];
                              //assigned variable a to the items
                              //alert(a) returns: [object Object][object Object]
                                var a = (items);
                                   //combine two arrays together
                                    var result=a.concat(b);
    //alert(result) returns: [object Object],[object Object],[object Object],[object Object],[object Object]                

                            //get all properties values of a Javascript Object
                            //source stackoverflow: http://stackoverflow.com/questions/7306669/how-to-get-all-properties-values-of-a-javascript-object-without-knowing-the-key
                            var keys = Object.keys(result);

                                //keys.length = 5
                                for (var i = 0; i < keys.length; i++) {
                                    var val = result[keys[i]];

                                    alert(val);
                                   //alert returns: [object Object]

                                   document.write(val[i] + "<br>");
                                   //doesn't return anything

                                   //I want to append the results to table here
                                  }
                            } 
    }

Both javascript objects have multiple and different properties:
Etsy: [{"listing_id":123,"title":"etsy","..."}]
Ebay: [{"itemId":["123"],"title":["ebay"],..,}]
Full Ebay and Etsy JSON result shown here
Question: How do I get the properties value of both arrays, I want to get the "title" property from both and append them into a table.

EDIT: Table format, my end goal here is to take the title, image and price from both arrays.

var trHTML = '';
$.each(keys, function(i,item) {
trHTML += '<tr><td>' + '<a href="'
+ item.url +'" target="_blank" style="color: white"><img src="' 
//unsure of the property names such as 'image'
                                + image + '" border="0"></a></td><td>' 
                                + title + '</td><td>' 
                                + price + '</td></tr>';
})
$('#result-table').append(trHTML);  

I am able to append the array seperately, the table format and names are as shown here.
The names of the properties are different for Etsy and Ebay enter image description here

Detective merry
  • 384
  • 1
  • 21
  • 1
    How do you intend to deal with the other properties in the table? Would help to see an intended table layout. In principle I would use `$.each(array, function...` in conjunction with directly accessing the properties, but be careful as there are objects mixed with arrays so to access your ebay title it's `var items = root.findItemsByKeywordsResponse[0].searchResult[0].item[0].title`, note the last `[0]` I imagine this counts up if there's more than one item so this is where I'd apply `$.each(...` – Sam0 Jan 24 '17 at 20:04
  • 1
    please show us your table structure. – tfidelis Jan 24 '17 at 21:14
  • I have added my table structure ! along some additional information I don't really know if it will be useful – Detective merry Jan 25 '17 at 03:51

0 Answers0