technopeasant
technopeasant

Reputation: 7939

jQuery for each value in a cookie

I've got a cookie and I need to pull it's values and run a function on each of them. Not sure about how to separate the values... so here's what I'm working with:

var cookie = [1,2,3],
    val = cookie.methodThatSplitsEachValueIntoASeparateObject;

val.each(function(){
    //I'm running on 1, 2, and 3!
});

Upvotes: 1

Views: 526

Answers (2)

tobspr
tobspr

Reputation: 8376

Maybee you iterate through the array?

for(var i=0;i<cookies.length;i++) {
//Create object from cookies[i]
}

Hope that helps.

Upvotes: 0

VisioN
VisioN

Reputation: 145398

Simple for loop:

for (var i = 0; i < cookie.length; i++) {
    var val = cookie[i];
    // alert(val);
}

jQuery each() method:

$.each(cookie, function(i, val) {
    // alert(val);
});

Upvotes: 2

Related Questions