1

in some other post I found that there should be limitation like 512mb (~2^27) for the maximum string length in javascript. I have the following code in my application:

i = 1;
selectionField.value = i;
i++;
for (i;i<=tableEntries;i++){
selectionField.value = selectionField.value + "," + i;
}

whereby "tableEntries" is e.g. "40000". This code executes fine in Firefox (though it takes around 5-10 seconds and prompts with a warning for a long running script) but does not execute in chrome. Chrome just interupts in this loop and says it cannot display the page. Is there a particular setting in chrome that can lead to this unexpected result? I mean the final string should have a length of ~240k chars. This should be fine according to the limit mentioned at the beginning.

Thanks for help in advance!

3
  • This might help : stackoverflow.com/questions/34957890/… Commented Oct 10, 2016 at 11:24
  • Just tested it out and I was able to run the loop in chrome console Commented Oct 10, 2016 at 11:24
  • Tested it in my chrome console , I too was able to run. Commented Oct 10, 2016 at 11:26

1 Answer 1

1

The problem is not with the length of the string, but that you're trying to update the value in the input field on screen 240k~ times.

A better solution would be to copy the field value to a variable, perform the string concatenation in-memory and then update the finished string only once in the DOM (on screen).

Adding to your code, it would be something like this:

i = 1;
var str = i;
i++;
for (i;i<=tableEntries;i++){
str = str + "," + i;
}
selectionField.value = str;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.