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 7503315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:10:50+00:00 2026-05-29T21:10:50+00:00

I have an application where I am using JavaScript on the client-side to build

  • 0

I have an application where I am using JavaScript on the client-side to build a collection. On page1.html I have the following:

var collection = []; 
$.each(item, function (i, r) {
  collection.push(r);
});
alert(collection.length);

window.localStorage.setItem("collection", collection);

When this code executes, I see “4” in a message box. This is exactly what I am expecting. When I navigate to page2.html, I have the following:

$(document).ready(function () {
  var collection = window.localStorage.getItem("collection");
  alert(collection.length);
});

When this code executes, I see “63” in a message box. I was expecting “4”. I have no idea what would cause this. My hunch is that it has something to do with the fact that I’m trying to store a collection and I’m not getting/setting like I should. This approach has worked for some purely string related values in my application. I’m not sure why its not working here though. Can anybody point me in the right direction?

Thanks!

  • 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-29T21:10:50+00:00Added an answer on May 29, 2026 at 9:10 pm

    localStorage can only be used to store objects as strings, so you’ll need to serialize your list as a string (perhaps using commas or a null character).

    One idea is to use jQuery’s JSON.stringify method on collection and store that.

    Feel free to check out this post for more information.

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

Sidebar

Related Questions

I am using external interface to store cookies in client side of application. Like
I'm trying to have client-side validation errors show up inline, using the client_side_validations gem
I have written some JavaScript to do client-side validation. If I press F5 to
I'm usually a C# developer, but writing a mostly-client side application using jQuery. It
I'm using MVC 3 with unobtrusive javascript for client validation. I have a table
I'm using Rob Monies 'Jquery Week Calendar' to build a calendar application. I have
I have been developed a web application using java servlet at server side and
Have you tried using straight javascript (rather straight ECMAscript 3 standard) in Flex applications,
I have an application using Core Data and bindings. I want to have an
We have an application using the IBM Informix driver. Whenever we try to open

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.