0

How do I create and read a value of array of objects from cookie in JavaScript?

[{name="sss", age="33"}
, {name="ll", age="22"}]
1
  • i have a project which i suppose to save data in table and this data in an object has e- mail and age ..etc , it's contact APP so i want when add new person to save his data , and i can not do this , when i search i also find just cookie for names ,,,, not = it's : sorry for this error Commented Feb 18, 2015 at 20:26

1 Answer 1

1

You'll have to "stringify" the array and store the string in the cookie, something like:

var myArray = [{name="sss", age="33"} , {name="ll", age="22"}];
var cookieStr = JSON.stringify(myArray);
// Do whatever you want with your cookie

Then you get the string back out later (as a string) and parse it:

var cookieStr = ...; // Get it out of the cookie
var myArray = JSON.parse(cookieStr);
Sign up to request clarification or add additional context in comments.

2 Comments

ok how can i loop on it , i have a large data
@mohamedosman: How to work with arrays is explained in the MDN JavaScript tutorial: developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.