Advertisement

06.22.2008 at 03:08PM PDT, ID: 23506218
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.4

Split Cookies into Assoc. Array or Object?

Asked by scrathcyboy in JavaScript

The standard way to read a multi-value cookie is into an associative array --

var cookie_data = new Array();
cookie_data = cookie_name.split(" | ");

This puts everything into name1=value1 pairs -- which makes it cumbersome to extract and replace values.  First you must search for the string "name=" then do complex substring work to extract the value (20+ lines of code).  To replace a value in the array is even harder, I haven't figured out how to do it yet, easily, that is.

Seems to me it is better to read a multi-item cookie into an OBJECT where the index position is known --

var cookie_data new Object;

Say we know there are 20 entries in the cookie data, the NAMES of each entry is '1' , '2' , '3', ... up to ... '20'

So in an object array,
var first_value = cookie_data ['1'];
var last_value = cookie_data ['20'];

gets the VALUES of the name=value pairs, using normal array indexing -- SO easy to understand and do.

This compares to arduous searching for "name=" strings to extract the following substring to get a value.  Why do that if you already know the name-position of each item in the array, why not just index its value?

QUESTIONS --
(1) why not use an Object instead of an associative array, especially if the field names are known, like 1,2,3 etc.?  If so, it is EASY to replace a known value with a new value  --   cookie_data ['6'] = updated_value;

(2)  If not, how do I update the value in an assoc. array easily, without a mass of code to search the array?

(3)  Can name=value pairs be retrieved and replaced from an array OBJECT as I've shown above, or not?  

(4) If not, please give CODE to show how it is done in an associative array -- I am struggling with it.  

(5) Why does everyone use assoc. arrays if it is easier to index a value of an entry by -- array['name'] ?

NO LINKS.  I searched > 200 articles on cookie arrays.  NO ONE shows how to update/change a value in an associative array .  If you know how to do it in either type of array, PLEASE POST YOUR CODE !!!  

BTW, I don't want to change the cookies directly. Too many many changes / edits, so it must be in a JS array --  only after all editing, is the new cookie written back to a file (i.e. no direct cookie writing). Thanks.Start Free Trial
 
 
[+][-]06.23.2008 at 12:51AM PDT, ID: 21844206

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Sign Up Now!
Solution Provided By: mplungjan
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.23.2008 at 01:03AM PDT, ID: 21844254

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.23.2008 at 10:30AM PDT, ID: 21848346

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.23.2008 at 10:35AM PDT, ID: 21848389

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.23.2008 at 01:34PM PDT, ID: 21850086

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.23.2008 at 02:17PM PDT, ID: 21850431

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.23.2008 at 02:27PM PDT, ID: 21850534

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.23.2008 at 03:43PM PDT, ID: 21851014

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.24.2008 at 02:28AM PDT, ID: 21853721

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906