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.
- function ArrayCollection() {
- var myArray = new Array;
- return {
- empty: function () {
- myArray.splice(0, myArray.length);
- },
- add: function (myElement) {
- myArray.push(myElement);
- }
- }
- }
- function usrSession(userID, cords, color) {
- this.UserID = userID;
- this.Cords = cords;
- this.Color = color;
- }
- usrSessionCollection = new ArrayCollection();
- $.getJSON(dataurl, function (data) {
- for (var x = 0; x < data.length; x++) {
- usrSessionCollection.add(new usrSession(data[x].usrID.toString(), data[x].usrcords.toString() ,data[x].color.toString());
- }
- });