javascript - Store Array to Cookie Jquery -


I am creating an array in my code that looks like this

array [" Type

When I save it in a cookie and read it again, it should be

come ["type, year, week"]

How do I keep the original form array ["type", "year", "week"] I think it is being snatched

Thank you in advance

My code:

  var myArray = ["Type",  

"year", "week" ] $ .cookie ('s Setup Cookie

< P> The cookies store the string values.

You need to sort your array (with JSON) or with a predefined delimiter before it gets it in the cookie For example:

// store cookie $ .cookie ('Setup', myArray.join ('|'), {Path: '/'}); Or $ .cookie ('Setup', JSON.stringify (myArray), {path: '/'}); Read from // cookie myArray = $ .cookie ('setup'). Division ('|'); Or myArray = JSON.parse ($ .cookie ('setup'));

Note : The JSON versions are protected because they will work with any type of array. Formerly assumes that your array elements include them in | is not.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -