Advanced search/remove object in array question

Advanced search/remove object in array question

I have a pretty large number of objects "usrSession" I store them in my ArrayCollection usrSessionCollection.

I'M looking for a function that returns the latest userSessions added with a unique userID. So something like this:

1. search the usrSessionCollection and only return one userSessions per userID.

2. When it has returned x number of userSessions then deleted them from the usrSessionCollection

I'M stuck - would really love some code that can help me with that.


  1. function ArrayCollection() {
  2. var myArray = new Array;
  3. return {
  4. empty: function () {
  5. myArray.splice(0, myArray.length);
  6. },
  7. add: function (myElement) {
  8. myArray.push(myElement);
  9. }
  10. }
  11. }

  12. function usrSession(userID, cords, color) {
  13. this.UserID = userID;
  14. this.Cords = cords;
  15. this.Color = color;
  16. }

  17. usrSessionCollection = new ArrayCollection();

  18. $.getJSON(dataurl, function (data) {
  19. for (var x = 0; x < data.length; x++) {
  20. usrSessionCollection.add(new usrSession(data[x].usrID.toString(), data[x].usrcords.toString() ,data[x].color.toString());
  21. }
  22. });