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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:01:49+00:00 2026-05-17T18:01:49+00:00

I’m rather confused at the moment, could someone explain this one to me? Maybe

  • 0

I’m rather confused at the moment, could someone explain this one to me? Maybe it’s something small I’m oblivious to, but I’m confused as to why this isn’t resulting as I expect it to.

I have created a samples to show the issue I’m seeing…

Sample 1

var dataString = "abc";

document.write(" This is a test ... " + "<br/>")
for (i in dataString ) {
    document.write("<br/> +" + dataString[i] + ": ")
    for (k in dataString ) {
        document.write(" ="+dataString[k] +", ");
    }
}
​

Now, my results in Chrome are:

This is a test ... 

+a: 
+b: 

In FireFox are: (This is the result I expected)

This is a test ... 

+a: =a, =b, =c, 
+b: =a, =b, =c, 
+c: =a, =b, =c, 

Results in IE8 are:

This is a test ... 

Can anyone explain to me what’s happening here? Have I missed something critical?

Note:
You can translate strings to arrays across browsers using "abc".split("") as per this example, just remember that this is no longer a string and now if you output it, it will be output as an array a,b,c

  • 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-17T18:01:50+00:00Added an answer on May 17, 2026 at 6:01 pm
    for (i in dataString ) {
        document.write("<br/> +" + dataString[i] + ": ")
    

    It is not part of the JavaScript standard(*) that strings should have their characters accessible as numbered properties; this is an extension originally introduced by Mozilla. Consequently dataString[i] will be undefined on older browsers including IE<8.

    To access a character in a string properly you should use charAt.

    For the same reason, for...in over a string won’t iterate over the indexes in all browsers.

    And even if it did, it would be the wrong thing to use, because for...in is for enumerating properties in an Object ({}) map, not iterating over sequences. for...in should not be used on an Array or String as you will get all the members of that instance, not just numeric-indexed ones, and there’s no guarantee you will get them in any particular order.

    For Array and String the correct loop is the old-school for i loop. And you should use var even if it’s a global variable.

    document.write(' This is a test ... <br/>');
    for (var i= 0; i<dataString.length; i++) {
        document.write('<br/> +'+dataString.charAt(i)+': ');
        for (var k= 0; k<dataString.length; k++) {
            document.write(' ='+dataString.charAt(k)+', ');
        }
    }
    

    (*: well… not in ECMAScript Third Edition. The new Fifth Edition states that Strings have ‘array index names’, which might be an endorsement of this feature. Seems a little unclear)

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

Sidebar

Related Questions

This could be a duplicate question, but I have no idea what search terms
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.