Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    listArray.length is not behaving correctly in IE10

    Hi All,
    Please someone look into the below mentioned issue.

    The problem is with IE10 browser.
    we assigning a JSon string value into a variable.
    (var listArray = eval(listItemCollectionJSONString). But while taking listArray.length in IE 10 it returns actual length-1. So in populating the list into a listbox the listitem-1 only able to

    view.
    While open the arraylist variable we can see an unwanted item (Prototype Array). In
    IE 9 this problem doesn't seem.

    Regards,
    Saju.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,614
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Don't use eval for the conversion.

    JavaScript provides JSON.parse() and JSON.stringify() for converting to and from JSON.

    var listArray = JSON.parse(listItemCollectionJSONString)
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    mrhoo (03-13-2014)

  • #3
    New to the CF scene
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried to apply this fix, but it showed some uncontrolled behavior. While taking the JSON string, I have noticed that in IE 10 data an extra "\" is coming in before the double quotes. For Ex:
    Actual Data : "[{ "Name" : "Device: Description", "Value" : "d9c9a19d-8137-da11-9c65-001143e66a7c" },{ "Name" : "Device: Dev Management Type [1]", "Value" : "79619a4f-32c0-da11-9b64-001143e66a7c" },]
    Ie 10 Data : "[{ \"Name\" : \"Device: Description\", \"Value\" : \"d9c9a19d-8137-da11-9c65-001143e66a7c\" },{ \"Name\" : \"Device: Dev Management Type [1]\", \"Value\" : \"79619a4f-32c0-da11-9b64-001143e66a7c\" },]

    In spite of this the array count is getting reduced by 1.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Quote Originally Posted by sajuthomas View Post
    I have tried to apply this fix, but it showed some uncontrolled behavior. While taking the JSON string, I have noticed that in IE 10 data an extra "\" is coming in before the double quotes. For Ex:
    Actual Data : "[{ "Name" : "Device: Description", "Value" : "d9c9a19d-8137-da11-9c65-001143e66a7c" },{ "Name" : "Device: Dev Management Type [1]", "Value" : "79619a4f-32c0-da11-9b64-001143e66a7c" },]
    Ie 10 Data : "[{ \"Name\" : \"Device: Description\", \"Value\" : \"d9c9a19d-8137-da11-9c65-001143e66a7c\" },{ \"Name\" : \"Device: Dev Management Type [1]\", \"Value\" : \"79619a4f-32c0-da11-9b64-001143e66a7c\" },]

    In spite of this the array count is getting reduced by 1.
    The problem is the extra comma in the array. I highlighted it in red above.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    ie10 fixed the jscript discrepancy with ecmascript where extra commas in array literals were not disposed of correctly.

    in IE<10:
    Code:
    [1,2,3,,].length == 5
    in IE10 and everywhere else:
    Code:
    [1,2,3,,].length == 4
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,614
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Quote Originally Posted by rnd me View Post
    ie10 fixed the jscript discrepancy with ecmascript where extra commas in array literals were not disposed of correctly.
    Strictly speaking since IE10 only supports JavaScript and not jScript it didn't fix the discrepancy in jScript. It is only browsers that support jScript where trailing commas increase the length. The only browser that supports JavaScript that miscounts the length when there are trailing commas is IE9 and that is because it also still mostly supports jScript with just enough jScript that it doesn't support to require special treatment in some circumstances. Fortunately IE9 is now effectively dead with most IE users either in the process of upgrading from IE10 to IE11 or still using the soon to be abandoned IE8.

    Of course none of this changes what you said - browsers using jScript will count the number of entries in an array differently to how JavaScript browsers do when there are trailing commas.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,294
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by felgall View Post
    Strictly speaking since IE10 only supports JavaScript and not jScript it didn't fix the discrepancy in jScript.
    the browser stopped screwing it up when it moved to JS. IE9 is not ecmascript compliant...
    anyway, would a rose by any other name not smell so sweet?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •