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

  • Home
  • SEARCH
  • 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 3235706
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:32:14+00:00 2026-05-17T17:32:14+00:00

I have a spurious problem which seems to indicate the index value got from

  • 0

I have a spurious problem which seems to indicate the index value got from the jquery each method does not always start at 0.

My javascript looks a bit like this:

$("#mylist").each(function(index) {
    var obj = new myclass();
    obj.property = "whatever";
    obj.sequence = index + 1;
    parentobj.list.push(obj);
});

This all gets packaged into json and ajaxed (please pardon verb usage) back to the server. The server then deserialises the json into .net objects. It’s at this point I get an error:

The value '91111' cannot be parsed as the type 'Int16'. 

This is at the point it tries to push the sequence value into a short field.

I cannot recreate this (always happens to other users). I may be able to add some debug code to the javascript files in question during a quiet period but there’s no guarantee it will happen then.

There also seems to be a strange pattern to the values. The values in the log are:
61111, 81111, 91111, 111111, 211111, 311111. These neither ascend or descend and sometimes repeat.

Can anyone shed a light on this or confirm that I cannot trust the index to start from zero?

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-17T17:32:15+00:00Added an answer on May 17, 2026 at 5:32 pm

    As quoted from the jquery API on .each():

    Each time the callback runs, it is
    passed the current loop iteration,
    beginning from 0

    I am assuming, therefore, that it is always indexed at 0. I have had strange problems with jQuery treating an operation of an int + 1 as a string concatenation (which could explain the digit followed by trailing ones in your errors). For example, look at the following code:

    var a = 1;
    var b = a + 1;
    

    With code similar to this, I would get 11. The solution is to wrap a in a parseInt(), like this:

    var a = 1;
    var b =  parseInt(a) + 1;
    

    Try modifying your code to the following and see what happens:

    $("#mylist").each(function(index) {
        var obj = new myclass();
        obj.property = "whatever";
        obj.sequence = parseInt(index) + 1;
        parentobj.list.push(obj);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you refactored from an ActiveRecord to a DataMapper pattern? What conditions prompted the
I have a visual studio (2005) solution file with 70 projects. Each time I
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have you determined a maximum number of characters allowed in FCKEditor ? I seem
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,

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.