Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think what's he's trying to do is join the two datasets as if they were tables, joining by the brandName. From what I've been testing jQuery's $.extend() function does not take care of that, but merges objects according to their index in the Object arrays that it receives.</p> <p>I think the matching of the key would need to be done manually.</p> <pre><code>stock = [{"brandName":"Fender","gearShiftedPerMonth":"35","retailSalesPerMonth":"55"}, {"brandName":"Gibson","gearShiftedPerMonth":"23","retailSalesPerMonth":"43"}, {"brandName":"Epiphone","gearShiftedPerMonth":"10","retailSalesPerMonth":"13"}]; value = [{"brandName":"Gibson","stockValue":"1234"}, {"brandName":"Fender","stockValue":"975"}, {"brandName":"Epiphone","stockValue":"834"}]; var results = []; $(stock).each(function(){ datum1 = this; $(value).each(function() { datum2 = this; if(datum1.brandName == datum2.brandName) results.push($.extend({}, datum1, datum2)); }); }); </code></pre> <p>Which would result in:</p> <pre><code>[{"brandName":"Fender","gearShiftedPerMonth":"35","retailSalesPerMonth":"55","stockValue":"975"}, {"brandName":"Gibson","gearShiftedPerMonth":"23","retailSalesPerMonth":"43","stockValue":"1234"}, {"brandName":"Epiphone","gearShiftedPerMonth":"10","retailSalesPerMonth":"13","stockValue":"834"}] </code></pre> <p>Instead of what the use of <code>$.extend()</code> returns:</p> <pre><code>[{"brandName":"Gibson","gearShiftedPerMonth":"35","retailSalesPerMonth":"55","stockValue":"1234"}, {"brandName":"Fender","gearShiftedPerMonth":"23","retailSalesPerMonth":"43","stockValue":"975"}, {"brandName":"Epiphone","gearShiftedPerMonth":"10","retailSalesPerMonth":"13","stockValue":"834"}] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload