Question: I have created the following script which loops over my cookie. When I find a match I want to remove just the matching value from the cookie. How do I achieve this?

```
 var cookieName = 'myCookie';
 var cookie = $.cookie("preferences");
 var cookie = cookie.split('|');

 $(cookie).each(function(index){
      var thisCookieData = this.split(',');
      if(thisCookieData[0] == thisWidget.id ){
           alert("Match!");
      }
      alert(thisCookieData);
 });

```

Answer: 
You can use this code:
````

    cookie = $.grep(cookie, function(item, index) {
        var parts = item.split(',');
        return parts[0] !== id;
    }).join('|');

````

grep is a jquery function which finds elements in an array which satisfies the given function.
split, remove and join again:

```
.split(',')
...
.join(',')

```