0

How to combine two Json feeds in one and display them in one timeline by date using JS or jQuery?

For example we will have two Json responses (one from twitter and another from google+).

I need "n" numbers of latest items and show append them to show by items time.

Any ideas or hints?

Thank you!

Konrad Krakowiak
  • 11,733
  • 10
  • 53
  • 44

1 Answers1

0

Get the #number latest results from each feed:

var json1 = [{id:1, name: 'xxx' ...}]
var json2 = [{id:2, name: 'xyz' ...}]

var finalObj = json1.concat(json2);

Use the .sort JavaScript method for sorting by date. You would need to create a custom compare function to check dates in both objects. Check out this old question for more information on sorting by date:

Sort Javascript Object Array By Date

Show only the first #number elements of the sorted array.

var numberToShow = n - 1;
for (i = 0, x = numberToShow; i < x; i++) { 
  console.log(i);
}
Community
  • 1
  • 1
andybeli
  • 746
  • 5
  • 13