Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 376779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:37:56+00:00 2026-05-12T14:37:56+00:00

This is royally annoying me at the moment: Consider an array of 2 values:

  • 0

This is royally annoying me at the moment:

Consider an array of 2 values:

var myArray = new Array();
myArray.push(21031);
myArray.push(21486);

When storing this in a cookie using jquery and toJSON, the value of the cookie looks like this:

["21031","21486"]

Now consider an array of a single value:

var myArray = new Array();
myArray.push(21239);

When storing this in a cookie using jquery and toJSON, the value of the cookie looks like this:

21239

This is almost completely useless to me as when I pull the items from the cookie, one comes back as a single value, the other comes back as an array that I can iterate over….ahhh!

Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:37:56+00:00Added an answer on May 12, 2026 at 2:37 pm

    I’d suggest using json2.js’ JSON.stringify. It gets both of those cases right:

    // [] is the same as new Array();
    var foo = [];
    
    foo.push(1);
    foo.push(2);
    
    JSON.stringify(foo); // "[1, 2]"
    
    var bar = [];
    
    bar.push(1);
    
    JSON.stringify(bar); // "[1]"
    

    In addition, when you use the json2.js API, your code automatically takes advantage of browser-native functionality in newer browsers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem has been bugging me since forever. I have an array and in
This is my bitmap object Bitmap b = new Bitmap(columns, rows, PixelFormat.Format8bppIndexed); BitmapData bmd
This is an open-end interview question. Given an array with 2 numbers are duplicated
This onclick function: VVi.$row['id']..onclick = function() { alert('1'); var ResultI = '.$row['id'].'; location.href='visuals.php?ResultI=' +
This is my code: OleDbConnection connection = new OleDbConnection( Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\Offline.accdb;Persist Security Info=False); connection.Open();
this is most likely very easy but i'm struggling $(window).bind(load resize, function(){ var wH
This is essentially what I want to do: public abstract class Uniform<T> { public
This more of a style question, rather than a how to. So I've got
This is a weired problem, I have implemented simple quick sort as follows.. static
This has been implemented in many websites lets say odesk or so.What I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.