/    Sign up×
Community /Pin to ProfileBookmark

cookie array question

Hi,
I’ve got an object that holds an array of all available cookies on a page.
I want to loop through that array, search for a set of cookies that I know by name. The may or may not be there in addition to other cookies. What I want to do is remove any cookies that are not the 5 that I want from the ojbect array, so that the array will only hold the 5 cookies that I want to deal with.

Only I’m not sure how to do this. I know this is probably totally off, but my guess is something like this…

[code]

<script>
var cookList = new cookieList(); //function that gathers all cookies on the page
for(i in cookList) {
if (cookList[i]) {
var ca = findCookieOjbect(“RA”, cookList); //function that will find a named cookie in the cookieList array
var cu = findCookieObject(“CU”, cookList);
var r = findCookieObject(“R”, cookList);
var ro = findCookieOjbect(“CA”, cookList);
var sp = findCookieOjbect(“SP”, cookList);
}
}
cookList[0] = ca;
cookList[1] = cu;
cookList[2] = r;
cookList[3] = ro;
cookList[4] = sp;

cookList.split(5, <5); // don’t know if I can do greater than 5 here
return cookList;
</script>

[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FromU2MEDec 07.2005 — To search through all cookies that belong to you - try this script:

[CODE]<script language="JavaScript">

allCookies = document.cookie.split("; ");

for (i=0; i<allCookies.length; i++) {

// Use allCookies[i] here to check current cookie

}

</script>[/CODE]
×

Success!

Help @taymond spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...