views:

48

answers:

1

I'm abit stuck.

I'm using jQuery.

I have a cookie which has the value such as :

1,something|2,somethingg|1,something

We are treating it as [0] as id and [1] as name.

I need to remove ONE where the id == '1' for example, this will leave the cookie like this:

1,something|2,somethingg

How do I go about this, it will probally be in a loop, but not sure how to remove one of them. I have this so far:

function removeItem(id){ 

var cookieName = 'myCookie';
 var cookie = $.cookie(cookieName);

 if(cookie){

  var cookie = cookie.split('|');




  $(cookie).each(function(index){

   var thisCookieData = this.split(',');



   if(thisCookieData[0] == id ){




   }

  });

}
A: 

You can call $.grep, like this:

cookie = $.grep(cookie, function(item, index){
    var parts = item.split(',');

    return parts[0] !== id;
}).join('|');
SLaks
I have solved the problem.
MgS
Then you should accept this answer by clicking the hollow check.
SLaks
Yeh, but yours isn't the answer...
MgS
Then you should have edited your question.
SLaks