jquery - Javascript join two json and compare -


i have code:

var json = '[{"id":113,"price":55,"start":"sun, 24 apr 2016 00:00:00 +0000","user_id":8},{"title":"","start":"2016-04-25t23:00:00.000z","price":"115.7"},{"title":"","start":"2016-05-06t23:00:00.000z","price":"115.7"},{"id":114,"price":45,"start":"sun, 08 may 2016 00:00:00 +0000","user_id":9},{"title":"","start":"2016-05-08t23:00:00.000z","price":"115.7"},{"id":111,"price":55,"start":"wed, 01 jun 2016 00:00:00 +0000","user_id":11},{"title":"","start":"2016-06-01t23:00:00.000z","price":"115.7"},{"id":110,"price":53,"start":"fri, 03 jun 2016 00:00:00 +0000","user_id":8}]';  moment.utc().valueof();   function fulljson(data) {    data = jquery.parsejson(data);     start = moment.utc('sun, 24 apr 2016 00:00:00 +0000').valueof()/86400000;    start = parseint(start);   console.log('pocetak'+start);    = moment.utc().valueof()/86400000;   = parseint(now);    console.log('sada'+now);    end = moment.utc('sun, 05 jun 2016 00:00:00 +0000').valueof()/86400000;    end = parseint(end);   console.log('kraj'+end);    auction_end = parseint('3');   = + auction_end;   console.log('a sada je '+now);    if (start > now) {     pocetak = start;     console.log(pocetak);   } else {     pocetak = now;     console.log(pocetak);   }  var array_of_all_dates = [];   (i = pocetak; < end; i++) {      var new_object = {                     title: '1',                     start: moment(i*86400000).utcoffset('+0000').format(),                     price: '{{$article->lowest_bid}}'                 };     array_of_all_dates.push(new_object); } document.write(json.stringify(array_of_all_dates));   console.log(array_of_all_dates); };   fulljson(json); 

so @ end see have json , array_of_all_dates. want join json array_of_all_dates if same start element excist array_of_all_dates remove array_of_all_dates , put json...

http://jsbin.com/qekijumobe/edit?html,js,output

how this? please help.

as far understand , interpret question

json

[      {         "id":113,       "price":55,       "start":"sun, 24 apr 2016 00:00:00 +0000",       "user_id":8    },    {         "title":"",       "start":"2016-04-25t23:00:00.000z",       "price":"115.7"    },    {         "title":"",       "start":"2016-05-06t23:00:00.000z",       "price":"115.7"    }, .. } 

and array_of_all_dates

[      {         "title":"1",       "start":"2016-04-24t00:00:00+00:00",       "day":16915,       "price":100    },    {         "title":"1",       "start":"2016-04-25t00:00:00+00:00",       "day":16916,       "price":100    },    {         "title":"1",       "start":"2016-04-26t00:00:00+00:00",       "day":16917,       "price":100    }, ... } 

so need join these two, without having duplicate "start" field. approach merge 2 json dataobjects, , remove duplicate start field items.

sample implementation in jquery:

lets append both lists 1 list called mergeditems then

var uniqueitems = []; $.each(mergeditems["start"], function(i, el){     if($.inarray(el, uniqueitems ) === -1) uniqueitems.push(el); }); 

edit: working example

http://jsbin.com/vakodahile/edit?html,js,output


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -